Skip to content

Commit f48f3fe

Browse files
hidavegregkh
authored andcommitted
driver-core: do not register a driver with bus_type not registered
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 <hidave.darkstar@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
1 parent e5779a5 commit f48f3fe

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

‎drivers/base/bus.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ int bus_register(struct bus_type *bus)
932932
kset_unregister(&bus->p->subsys);
933933
kfree(bus->p);
934934
out:
935+
bus->p = NULL;
935936
return retval;
936937
}
937938
EXPORT_SYMBOL_GPL(bus_register);
@@ -953,6 +954,7 @@ void bus_unregister(struct bus_type *bus)
953954
bus_remove_file(bus, &bus_attr_uevent);
954955
kset_unregister(&bus->p->subsys);
955956
kfree(bus->p);
957+
bus->p = NULL;
956958
}
957959
EXPORT_SYMBOL_GPL(bus_unregister);
958960

‎drivers/base/driver.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ int driver_register(struct device_driver *drv)
216216
int ret;
217217
struct device_driver *other;
218218

219+
BUG_ON(!drv->bus->p);
220+
219221
if ((drv->bus->probe && drv->probe) ||
220222
(drv->bus->remove && drv->remove) ||
221223
(drv->bus->shutdown && drv->shutdown))

0 commit comments

Comments
 (0)