[PATCH 40/61] driver-core: do not register a driver with bus_type not registered

From: Greg Kroah-Hartman
Date: Tue Mar 24 2009 - 20:44:20 EST


From: Dave Young <hidave.darkstar@xxxxxxxxx>

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@xxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxx>
---
drivers/base/bus.c | 2 ++
drivers/base/driver.c | 2 ++
2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 8547b78..11463c0 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -932,6 +932,7 @@ bus_uevent_fail:
kset_unregister(&bus->p->subsys);
kfree(bus->p);
out:
+ bus->p = NULL;
return retval;
}
EXPORT_SYMBOL_GPL(bus_register);
@@ -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);

diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 1e2bda7..2889ad5 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -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))
--
1.6.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/