aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/bus.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base/bus.c')
-rw-r--r--drivers/base/bus.c42
1 files changed, 37 insertions, 5 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index ab53832d57e5..03204bfd17af 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -156,7 +156,9 @@ static ssize_t driver_unbind(struct device_driver *drv,
156 device_release_driver(dev); 156 device_release_driver(dev);
157 err = count; 157 err = count;
158 } 158 }
159 return err; 159 if (err)
160 return err;
161 return count;
160} 162}
161static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind); 163static DRIVER_ATTR(unbind, S_IWUSR, NULL, driver_unbind);
162 164
@@ -358,7 +360,7 @@ int bus_add_device(struct device * dev)
358 if (bus) { 360 if (bus) {
359 pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id); 361 pr_debug("bus %s: add device %s\n", bus->name, dev->bus_id);
360 device_attach(dev); 362 device_attach(dev);
361 klist_add_tail(&bus->klist_devices, &dev->knode_bus); 363 klist_add_tail(&dev->knode_bus, &bus->klist_devices);
362 error = device_add_attrs(bus, dev); 364 error = device_add_attrs(bus, dev);
363 if (!error) { 365 if (!error) {
364 sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id); 366 sysfs_create_link(&bus->devices.kobj, &dev->kobj, dev->bus_id);
@@ -446,7 +448,7 @@ int bus_add_driver(struct device_driver * drv)
446 } 448 }
447 449
448 driver_attach(drv); 450 driver_attach(drv);
449 klist_add_tail(&bus->klist_drivers, &drv->knode_bus); 451 klist_add_tail(&drv->knode_bus, &bus->klist_drivers);
450 module_add_driver(drv->owner, drv); 452 module_add_driver(drv->owner, drv);
451 453
452 driver_add_attrs(bus, drv); 454 driver_add_attrs(bus, drv);
@@ -566,6 +568,36 @@ static void bus_remove_attrs(struct bus_type * bus)
566 } 568 }
567} 569}
568 570
571static void klist_devices_get(struct klist_node *n)
572{
573 struct device *dev = container_of(n, struct device, knode_bus);
574
575 get_device(dev);
576}
577
578static void klist_devices_put(struct klist_node *n)
579{
580 struct device *dev = container_of(n, struct device, knode_bus);
581
582 put_device(dev);
583}
584
585static void klist_drivers_get(struct klist_node *n)
586{
587 struct device_driver *drv = container_of(n, struct device_driver,
588 knode_bus);
589
590 get_driver(drv);
591}
592
593static void klist_drivers_put(struct klist_node *n)
594{
595 struct device_driver *drv = container_of(n, struct device_driver,
596 knode_bus);
597
598 put_driver(drv);
599}
600
569/** 601/**
570 * bus_register - register a bus with the system. 602 * bus_register - register a bus with the system.
571 * @bus: bus. 603 * @bus: bus.
@@ -600,8 +632,8 @@ int bus_register(struct bus_type * bus)
600 if (retval) 632 if (retval)
601 goto bus_drivers_fail; 633 goto bus_drivers_fail;
602 634
603 klist_init(&bus->klist_devices); 635 klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put);
604 klist_init(&bus->klist_drivers); 636 klist_init(&bus->klist_drivers, klist_drivers_get, klist_drivers_put);
605 bus_add_attrs(bus); 637 bus_add_attrs(bus);
606 638
607 pr_debug("bus type '%s' registered\n", bus->name); 639 pr_debug("bus type '%s' registered\n", bus->name);