On Tue, Aug 25, 2015 at 08:33:55AM -0400, Jes Sorensen wrote: > Sudip Mukherjee <sudipm.mukherjee@xxxxxxxxx> writes: > > On Tue, Aug 18, 2015 at 03:14:02PM -0400, Benjamin Romer wrote: > >> In cases where visorbus is compiled directly into the kernel, if > >> visorbus registration fails for any reason, it is still possible for > >> other drivers to call visorbus_register_visor_driver(), which could > >> cause an oops. Prevent this by returning an error code when the bus > >> hasn't been registered. > >> > >> Signed-off-by: Benjamin Romer <benjamin.romer@xxxxxxxxxx> > >> --- > >> drivers/staging/unisys/visorbus/visorbus_main.c | 3 +++ > >> 1 file changed, 3 insertions(+) > >> > >> diff --git a/drivers/staging/unisys/visorbus/visorbus_main.c b/drivers/staging/unisys/visorbus/visorbus_main.c > >> index 7905ea9..ad2b1ac 100644 > >> --- a/drivers/staging/unisys/visorbus/visorbus_main.c > >> +++ b/drivers/staging/unisys/visorbus/visorbus_main.c > >> @@ -863,6 +863,9 @@ int visorbus_register_visor_driver(struct visor_driver *drv) > >> { > >> int rc = 0; > >> > >> + if (!visorbus_type.p) > >> + return -ENODEV; /*can't register on a nonexistent bus*/ > >> + > > IIRC, Greg once told that we should not be working with the internal > > data structures of struct bus_type. > > If you looked at the code you would have noticed this is in fact the bus > driver, and visorbus_type is defined in this file. I guess we could tell > visorbus_main.c to not touch visorbus_type by deleting the file > completely ..... Yes, this is the bus driver, struct bus_type. Maybe the following might be a better approach where the struct bus_type internals are not touched yet it will server the purpose. regards sudip diff --git a/drivers/staging/unisys/visorbus/visorbus_main.c b/drivers/staging/unisys/visorbus/visorbus_main.c index 2309f5f..32500be 100644 --- a/drivers/staging/unisys/visorbus/visorbus_main.c +++ b/drivers/staging/unisys/visorbus/visorbus_main.c @@ -31,6 +31,7 @@ static int visorbus_debug; static int visorbus_forcematch; static int visorbus_forcenomatch; static int visorbus_debugref; +static bool bus_registered; #define SERIALLOOPBACKCHANADDR (100 * 1024 * 1024) #define CURRENT_FILE_PC VISOR_BUS_PC_visorbus_main_c @@ -40,6 +41,7 @@ static int visorbus_debugref; static int visorbus_uevent(struct device *xdev, struct kobj_uevent_env *env); static int visorbus_match(struct device *xdev, struct device_driver *xdrv); static void fix_vbus_dev_info(struct visor_device *visordev); +static bool is_visorbus_registered(void); /* BUS type attributes * @@ -863,6 +865,9 @@ int visorbus_register_visor_driver(struct visor_driver *drv) { int rc = 0; + if(!is_visorbus_registered()) + return -ENODEV; /*can't register on a nonexistent bus*/ + drv->driver.name = drv->name; drv->driver.bus = &visorbus_type; drv->driver.probe = visordriver_probe_device; @@ -1263,7 +1268,17 @@ create_bus_type(void) int rc = 0; rc = bus_register(&visorbus_type); - return rc; + + if (rc) + return rc; + bus_registered = true; + return 0; +} + +static bool +is_visorbus_registered(void) +{ + return bus_registered; } /** Remove the one-and-only one instance of the visor bus type (visorbus_type). _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel