浏览代码

staging: unisys: stop device registration before visorbus registration

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 saving the result of the call to
create_bus() in a static variable, and return an error code when the bus
hasn't been registered successfully.

Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Benjamin Romer 10 年之前
父节点
当前提交
6155a3cf11
共有 1 个文件被更改,包括 7 次插入4 次删除
  1. 7 4
      drivers/staging/unisys/visorbus/visorbus_main.c

+ 7 - 4
drivers/staging/unisys/visorbus/visorbus_main.c

@@ -37,6 +37,8 @@ static int visorbus_debugref;
 #define POLLJIFFIES_TESTWORK         100
 #define POLLJIFFIES_TESTWORK         100
 #define POLLJIFFIES_NORMALCHANNEL     10
 #define POLLJIFFIES_NORMALCHANNEL     10
 
 
+static int busreg_rc = -ENODEV; /* stores the result from bus registration */
+
 static int visorbus_uevent(struct device *xdev, struct kobj_uevent_env *env);
 static int visorbus_uevent(struct device *xdev, struct kobj_uevent_env *env);
 static int visorbus_match(struct device *xdev, struct device_driver *xdrv);
 static int visorbus_match(struct device *xdev, struct device_driver *xdrv);
 static void fix_vbus_dev_info(struct visor_device *visordev);
 static void fix_vbus_dev_info(struct visor_device *visordev);
@@ -863,6 +865,9 @@ int visorbus_register_visor_driver(struct visor_driver *drv)
 {
 {
 	int rc = 0;
 	int rc = 0;
 
 
+	if (busreg_rc < 0)
+		return -ENODEV; /*can't register on a nonexistent bus*/
+
 	drv->driver.name = drv->name;
 	drv->driver.name = drv->name;
 	drv->driver.bus = &visorbus_type;
 	drv->driver.bus = &visorbus_type;
 	drv->driver.probe = visordriver_probe_device;
 	drv->driver.probe = visordriver_probe_device;
@@ -1262,10 +1267,8 @@ remove_bus_instance(struct visor_device *dev)
 static int
 static int
 create_bus_type(void)
 create_bus_type(void)
 {
 {
-	int rc = 0;
-
-	rc = bus_register(&visorbus_type);
-	return rc;
+	busreg_rc = bus_register(&visorbus_type);
+	return busreg_rc;
 }
 }
 
 
 /** Remove the one-and-only one instance of the visor bus type (visorbus_type).
 /** Remove the one-and-only one instance of the visor bus type (visorbus_type).