aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@suse.de>2007-11-01 16:31:26 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2008-01-24 23:40:16 -0500
commit6dcec2511ff55b4abaca7ad3433011a7c04c2430 (patch)
treeaeb9c18a877987478a1594d42b8f041ebb388875
parent3d8995963dfec66ef6270e729bf75903e9043f9d (diff)
kset: convert struct bus_device->drivers to use kset_create
Dynamically create the kset instead of declaring it statically. Having 3 static kobjects in one structure is not only foolish, but ripe for nasty race conditions if handled improperly. We also rename the field to catch any potential users of it (not that there should be outside of the driver core...) Cc: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r--drivers/base/bus.c15
-rw-r--r--drivers/base/driver.c2
-rw-r--r--include/linux/device.h2
3 files changed, 10 insertions, 9 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index b23eeb2d4ead..6796d3e46053 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -638,7 +638,7 @@ int bus_add_driver(struct device_driver *drv)
638 error = kobject_set_name(&drv->kobj, "%s", drv->name); 638 error = kobject_set_name(&drv->kobj, "%s", drv->name);
639 if (error) 639 if (error)
640 goto out_put_bus; 640 goto out_put_bus;
641 drv->kobj.kset = &bus->drivers; 641 drv->kobj.kset = bus->drivers_kset;
642 drv->kobj.ktype = &driver_ktype; 642 drv->kobj.ktype = &driver_ktype;
643 error = kobject_register(&drv->kobj); 643 error = kobject_register(&drv->kobj);
644 if (error) 644 if (error)
@@ -869,11 +869,12 @@ int bus_register(struct bus_type * bus)
869 goto bus_devices_fail; 869 goto bus_devices_fail;
870 } 870 }
871 871
872 kobject_set_name(&bus->drivers.kobj, "drivers"); 872 bus->drivers_kset = kset_create_and_add("drivers", NULL,
873 bus->drivers.kobj.parent = &bus->subsys.kobj; 873 &bus->subsys.kobj);
874 retval = kset_register(&bus->drivers); 874 if (!bus->drivers_kset) {
875 if (retval) 875 retval = -ENOMEM;
876 goto bus_drivers_fail; 876 goto bus_drivers_fail;
877 }
877 878
878 klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); 879 klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put);
879 klist_init(&bus->klist_drivers, NULL, NULL); 880 klist_init(&bus->klist_drivers, NULL, NULL);
@@ -893,7 +894,7 @@ int bus_register(struct bus_type * bus)
893bus_attrs_fail: 894bus_attrs_fail:
894 remove_probe_files(bus); 895 remove_probe_files(bus);
895bus_probe_files_fail: 896bus_probe_files_fail:
896 kset_unregister(&bus->drivers); 897 kset_unregister(bus->drivers_kset);
897bus_drivers_fail: 898bus_drivers_fail:
898 kset_unregister(bus->devices_kset); 899 kset_unregister(bus->devices_kset);
899bus_devices_fail: 900bus_devices_fail:
@@ -916,7 +917,7 @@ void bus_unregister(struct bus_type * bus)
916 pr_debug("bus %s: unregistering\n", bus->name); 917 pr_debug("bus %s: unregistering\n", bus->name);
917 bus_remove_attrs(bus); 918 bus_remove_attrs(bus);
918 remove_probe_files(bus); 919 remove_probe_files(bus);
919 kset_unregister(&bus->drivers); 920 kset_unregister(bus->drivers_kset);
920 kset_unregister(bus->devices_kset); 921 kset_unregister(bus->devices_kset);
921 bus_remove_file(bus, &bus_attr_uevent); 922 bus_remove_file(bus, &bus_attr_uevent);
922 subsystem_unregister(&bus->subsys); 923 subsystem_unregister(&bus->subsys);
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index eb11475293ed..1c9770dfb801 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -185,7 +185,7 @@ void driver_unregister(struct device_driver * drv)
185 */ 185 */
186struct device_driver *driver_find(const char *name, struct bus_type *bus) 186struct device_driver *driver_find(const char *name, struct bus_type *bus)
187{ 187{
188 struct kobject *k = kset_find_obj(&bus->drivers, name); 188 struct kobject *k = kset_find_obj(bus->drivers_kset, name);
189 if (k) 189 if (k)
190 return to_drv(k); 190 return to_drv(k);
191 return NULL; 191 return NULL;
diff --git a/include/linux/device.h b/include/linux/device.h
index 82c277771376..110ace0dec3f 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -54,7 +54,7 @@ struct bus_type {
54 struct module * owner; 54 struct module * owner;
55 55
56 struct kset subsys; 56 struct kset subsys;
57 struct kset drivers; 57 struct kset *drivers_kset;
58 struct kset *devices_kset; 58 struct kset *devices_kset;
59 struct klist klist_devices; 59 struct klist klist_devices;
60 struct klist klist_drivers; 60 struct klist klist_drivers;