2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-11-19 08:05:27 +08:00

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>
This commit is contained in:
Greg Kroah-Hartman 2007-11-01 13:31:26 -07:00
parent 3d8995963d
commit 6dcec2511f
3 changed files with 10 additions and 9 deletions

View File

@ -638,7 +638,7 @@ int bus_add_driver(struct device_driver *drv)
error = kobject_set_name(&drv->kobj, "%s", drv->name); error = kobject_set_name(&drv->kobj, "%s", drv->name);
if (error) if (error)
goto out_put_bus; goto out_put_bus;
drv->kobj.kset = &bus->drivers; drv->kobj.kset = bus->drivers_kset;
drv->kobj.ktype = &driver_ktype; drv->kobj.ktype = &driver_ktype;
error = kobject_register(&drv->kobj); error = kobject_register(&drv->kobj);
if (error) if (error)
@ -869,11 +869,12 @@ int bus_register(struct bus_type * bus)
goto bus_devices_fail; goto bus_devices_fail;
} }
kobject_set_name(&bus->drivers.kobj, "drivers"); bus->drivers_kset = kset_create_and_add("drivers", NULL,
bus->drivers.kobj.parent = &bus->subsys.kobj; &bus->subsys.kobj);
retval = kset_register(&bus->drivers); if (!bus->drivers_kset) {
if (retval) retval = -ENOMEM;
goto bus_drivers_fail; goto bus_drivers_fail;
}
klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put); klist_init(&bus->klist_devices, klist_devices_get, klist_devices_put);
klist_init(&bus->klist_drivers, NULL, NULL); klist_init(&bus->klist_drivers, NULL, NULL);
@ -893,7 +894,7 @@ int bus_register(struct bus_type * bus)
bus_attrs_fail: bus_attrs_fail:
remove_probe_files(bus); remove_probe_files(bus);
bus_probe_files_fail: bus_probe_files_fail:
kset_unregister(&bus->drivers); kset_unregister(bus->drivers_kset);
bus_drivers_fail: bus_drivers_fail:
kset_unregister(bus->devices_kset); kset_unregister(bus->devices_kset);
bus_devices_fail: bus_devices_fail:
@ -916,7 +917,7 @@ void bus_unregister(struct bus_type * bus)
pr_debug("bus %s: unregistering\n", bus->name); pr_debug("bus %s: unregistering\n", bus->name);
bus_remove_attrs(bus); bus_remove_attrs(bus);
remove_probe_files(bus); remove_probe_files(bus);
kset_unregister(&bus->drivers); kset_unregister(bus->drivers_kset);
kset_unregister(bus->devices_kset); kset_unregister(bus->devices_kset);
bus_remove_file(bus, &bus_attr_uevent); bus_remove_file(bus, &bus_attr_uevent);
subsystem_unregister(&bus->subsys); subsystem_unregister(&bus->subsys);

View File

@ -185,7 +185,7 @@ void driver_unregister(struct device_driver * drv)
*/ */
struct device_driver *driver_find(const char *name, struct bus_type *bus) struct device_driver *driver_find(const char *name, struct bus_type *bus)
{ {
struct kobject *k = kset_find_obj(&bus->drivers, name); struct kobject *k = kset_find_obj(bus->drivers_kset, name);
if (k) if (k)
return to_drv(k); return to_drv(k);
return NULL; return NULL;

View File

@ -54,7 +54,7 @@ struct bus_type {
struct module * owner; struct module * owner;
struct kset subsys; struct kset subsys;
struct kset drivers; struct kset *drivers_kset;
struct kset *devices_kset; struct kset *devices_kset;
struct klist klist_devices; struct klist klist_devices;
struct klist klist_drivers; struct klist klist_drivers;