Skip to content

Commit

Permalink
Driver core: Fix error handling in bus_add_driver().
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
Cornelia Huck authored and Greg Kroah-Hartman committed Feb 21, 2008
1 parent 7199677 commit 0763446
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,17 +658,18 @@ 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;
priv->kobj.kset = bus->p->drivers_kset;
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);
Expand Down

0 comments on commit 0763446

Please sign in to comment.