intel_th: Fix activating a subdevice without a driver
authorAlexander Shishkin <alexander.shishkin@linux.intel.com>
Mon, 7 Mar 2016 15:04:45 +0000 (17:04 +0200)
committerAlexander Shishkin <alexander.shishkin@linux.intel.com>
Fri, 8 Apr 2016 13:11:58 +0000 (16:11 +0300)
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>
drivers/hwtracing/intel_th/core.c
drivers/hwtracing/intel_th/intel_th.h

index db0691929a608b450fb176c28948d89392871347..20339470c2c6ad55facfe94c74475c13f8d395ba 100644 (file)
@@ -183,7 +183,11 @@ static DEVICE_ATTR_RO(port);
 
 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)
                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)
 {
-       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)
                thdrv->deactivate(thdev);
index 15ebd48a29f2a0c39c0a5a3c5a2b850df4ca74f4..0df22e30673d9ac876d28379d2240ca80d4d21fb 100644 (file)
@@ -151,6 +151,9 @@ struct intel_th_driver {
 #define to_intel_th_driver(_d)                                 \
        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 *
 to_intel_th_hub(struct intel_th_device *thdev)
 {