浏览代码

intel_th: Fix activating a subdevice without a driver

If output subdevice driver is not loaded, activating it will try to
call its ->activate method and crash. Fix this by explicitly checking
for the driver.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Reviewed-by: Laurent Fert <laurent.fert@intel.com>
Alexander Shishkin 9 年之前
父节点
当前提交
f18a9531f6
共有 2 个文件被更改,包括 13 次插入2 次删除
  1. 10 2
      drivers/hwtracing/intel_th/core.c
  2. 3 0
      drivers/hwtracing/intel_th/intel_th.h

+ 10 - 2
drivers/hwtracing/intel_th/core.c

@@ -183,7 +183,11 @@ static DEVICE_ATTR_RO(port);
 
 
 static int intel_th_output_activate(struct intel_th_device *thdev)
 static int intel_th_output_activate(struct intel_th_device *thdev)
 {
 {
-	struct intel_th_driver *thdrv = to_intel_th_driver(thdev->dev.driver);
+	struct intel_th_driver *thdrv =
+		to_intel_th_driver_or_null(thdev->dev.driver);
+
+	if (!thdrv)
+		return -ENODEV;
 
 
 	if (thdrv->activate)
 	if (thdrv->activate)
 		return thdrv->activate(thdev);
 		return thdrv->activate(thdev);
@@ -195,7 +199,11 @@ static int intel_th_output_activate(struct intel_th_device *thdev)
 
 
 static void intel_th_output_deactivate(struct intel_th_device *thdev)
 static void intel_th_output_deactivate(struct intel_th_device *thdev)
 {
 {
-	struct intel_th_driver *thdrv = to_intel_th_driver(thdev->dev.driver);
+	struct intel_th_driver *thdrv =
+		to_intel_th_driver_or_null(thdev->dev.driver);
+
+	if (!thdrv)
+		return;
 
 
 	if (thdrv->deactivate)
 	if (thdrv->deactivate)
 		thdrv->deactivate(thdev);
 		thdrv->deactivate(thdev);

+ 3 - 0
drivers/hwtracing/intel_th/intel_th.h

@@ -151,6 +151,9 @@ struct intel_th_driver {
 #define to_intel_th_driver(_d)					\
 #define to_intel_th_driver(_d)					\
 	container_of((_d), struct intel_th_driver, driver)
 	container_of((_d), struct intel_th_driver, driver)
 
 
+#define to_intel_th_driver_or_null(_d)		\
+	((_d) ? to_intel_th_driver(_d) : NULL)
+
 static inline struct intel_th_device *
 static inline struct intel_th_device *
 to_intel_th_hub(struct intel_th_device *thdev)
 to_intel_th_hub(struct intel_th_device *thdev)
 {
 {