Skip to content

Commit

Permalink
driver-core: do not register a driver with bus_type not registered
Browse files Browse the repository at this point in the history
If the bus_type is not registerd, driver_register to that bus will cause oops.

I found this bug when test built-in usb serial drivers (ie. aircable driver)
with 'nousb' cmdline params.

In this patch:
1. set the bus->p=NULL when bus_register failed and unregisterd.
2. if bus->p is NULL, driver_register BUG_ON will be triggered.

Signed-off-by: Dave Young <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
hidave authored and gregkh committed Mar 24, 2009
1 parent e5779a5 commit f48f3fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions drivers/base/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,7 @@ int bus_register(struct bus_type *bus)
kset_unregister(&bus->p->subsys);
kfree(bus->p);
out:
bus->p = NULL;
return retval;
}
EXPORT_SYMBOL_GPL(bus_register);
Expand All @@ -953,6 +954,7 @@ void bus_unregister(struct bus_type *bus)
bus_remove_file(bus, &bus_attr_uevent);
kset_unregister(&bus->p->subsys);
kfree(bus->p);
bus->p = NULL;
}
EXPORT_SYMBOL_GPL(bus_unregister);

Expand Down
2 changes: 2 additions & 0 deletions drivers/base/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ int driver_register(struct device_driver *drv)
int ret;
struct device_driver *other;

BUG_ON(!drv->bus->p);

if ((drv->bus->probe && drv->probe) ||
(drv->bus->remove && drv->remove) ||
(drv->bus->shutdown && drv->shutdown))
Expand Down

0 comments on commit f48f3fe

Please sign in to comment.