Skip to content

Commit

Permalink
Driver Core: do not oops when driver_unregister() is called for unreg…
Browse files Browse the repository at this point in the history
…istered drivers

We also fix a problem with cleaning up properly when initializing
drivers and devices, so checks like this will work successfully.

Portions of the patch by Linus and Greg and Ingo.

Reported-by: Ozan Çağlayan <ozan@pardus.org.tr>
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Kay Sievers authored and Greg Kroah-Hartman committed May 28, 2009
1 parent 086a377 commit 5c8563d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,10 @@ int bus_add_driver(struct device_driver *drv)
}

kobject_uevent(&priv->kobj, KOBJ_ADD);
return error;
return 0;
out_unregister:
kfree(drv->p);
drv->p = NULL;
kobject_put(&priv->kobj);
out_put_bus:
bus_put(bus);
Expand Down
5 changes: 4 additions & 1 deletion drivers/base/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ int device_add(struct device *dev)
}

if (!dev_name(dev))
goto done;
goto name_error;

pr_debug("device: '%s': %s\n", dev_name(dev), __func__);

Expand Down Expand Up @@ -978,6 +978,9 @@ int device_add(struct device *dev)
cleanup_device_parent(dev);
if (parent)
put_device(parent);
name_error:
kfree(dev->p);
dev->p = NULL;
goto done;
}

Expand Down
4 changes: 4 additions & 0 deletions drivers/base/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ EXPORT_SYMBOL_GPL(driver_register);
*/
void driver_unregister(struct device_driver *drv)
{
if (!drv || !drv->p) {
WARN(1, "Unexpected driver unregister!\n");
return;
}
driver_remove_groups(drv, drv->groups);
bus_remove_driver(drv);
}
Expand Down

0 comments on commit 5c8563d

Please sign in to comment.