Re: [PATCH] Driver Core patches for 2.6.6

Greg KH
2004-05-14T23:10:56Z

ChangeSet 1.1587.5.21, 2004/05/05 15:10:00-07:00, bellucda@tiscali.it

[PATCH] missing audit in bus_register()

|How about using a goto on the error path to clean up properly
|instead of the different return sections.

.. here goes Take 2:

drivers/base/bus.c | 21 ++++++++++++++++++---
1 files changed, 18 insertions(+), 3 deletions(-)

diff -Nru a/drivers/base/bus.c b/drivers/base/bus.c
--- a/drivers/base/bus.c Fri May 14 15:57:45 2004
+++ b/drivers/base/bus.c Fri May 14 15:57:45 2004
@@ -555,21 +555,36 @@
*/
int bus_register(struct bus_type * bus)
{
+ int retval;
+
kobject_set_name(&bus->subsys.kset.kobj,bus->name);
subsys_set_kset(bus,bus_subsys);
- subsystem_register(&bus->subsys);
+ retval = subsystem_register(&bus->subsys);
+ if (retval)
+ goto out;

kobject_set_name(&bus->devices.kobj, "devices");
bus->devices.subsys = &bus->subsys;
- kset_register(&bus->devices);
+ retval = kset_register(&bus->devices);
+ if (retval)
+ goto bus_devices_fail;

kobject_set_name(&bus->drivers.kobj, "drivers");
bus->drivers.subsys = &bus->subsys;
bus->drivers.ktype = &ktype_driver;
- kset_register(&bus->drivers);
+ retval = kset_register(&bus->drivers);
+ if (retval)
+ goto bus_drivers_fail;

pr_debug("bus type '%s' registered\n",bus->name);
return 0;
+
+bus_drivers_fail:
+ kset_unregister(&bus->devices);
+bus_devices_fail:
+ subsystem_unregister(&bus->subsys);
+out:
+ return retval;
}