Driver core: Fix error handling in bus_add_driver().
authorCornelia Huck <cornelia.huck@de.ibm.com>
Mon, 18 Feb 2008 16:04:25 +0000 (17:04 +0100)
committerGreg Kroah-Hartman <gregkh@suse.de>
Thu, 21 Feb 2008 23:27:07 +0000 (15:27 -0800)
- If the allocation of ->priv fails, the reference on the bus
  must be dropped.
- If adding the kobject fails, kobject_put must be called to
  clean things up.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/base/bus.c

index 055989e94799eff3fb6e0b44823835257e8feb28..2d207ad303367ac12adb58ef795b6f622bd11789 100644 (file)
@@ -658,9 +658,10 @@ int bus_add_driver(struct device_driver *drv)
        pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name);
 
        priv = kzalloc(sizeof(*priv), GFP_KERNEL);
-       if (!priv)
-               return -ENOMEM;
-
+       if (!priv) {
+               error = -ENOMEM;
+               goto out_put_bus;
+       }
        klist_init(&priv->klist_devices, NULL, NULL);
        priv->driver = drv;
        drv->p = priv;
@@ -668,7 +669,7 @@ int bus_add_driver(struct device_driver *drv)
        error = kobject_init_and_add(&priv->kobj, &driver_ktype, NULL,
                                     "%s", drv->name);
        if (error)
-               goto out_put_bus;
+               goto out_unregister;
 
        if (drv->bus->p->drivers_autoprobe) {
                error = driver_attach(drv);