diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 69782d2..e2204da 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -25,9 +25,19 @@ int bus_register(struct bus_type *bus) { + int ret; + if (get_bus_by_name(bus->name)) return -EEXIST; + strcpy(bus->dev.name, bus->name); + bus->dev.id = DEVICE_ID_SINGLE; + + ret = register_device(&bus->dev); + if (ret) + return ret; + + INIT_LIST_HEAD(&bus->device_list); INIT_LIST_HEAD(&bus->driver_list); diff --git a/drivers/base/driver.c b/drivers/base/driver.c index dc2df91..c2e6819 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -125,6 +125,11 @@ if (!new_device->bus) return 0; + if (!new_device->parent) { + new_device->parent = &new_device->bus->dev; + dev_add_child(new_device->parent, new_device); + } + list_add_tail(&new_device->bus_list, &new_device->bus->device_list); bus_for_each_driver(new_device->bus, drv) { diff --git a/include/driver.h b/include/driver.h index f8d815c..0a5c69e 100644 --- a/include/driver.h +++ b/include/driver.h @@ -393,6 +393,8 @@ int (*probe)(struct device_d *dev); void (*remove)(struct device_d *dev); + struct device_d dev; + struct list_head list; struct list_head device_list; struct list_head driver_list;