thermal/core: Protect hwmon accesses to thermal operations with thermal zone mutex
authorGuenter Roeck <linux@roeck-us.net>
Thu, 10 Nov 2022 15:24:57 +0000 (07:24 -0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 14 Nov 2022 18:04:37 +0000 (19:04 +0100)
In preparation to protecting access to thermal operations against thermal
zone device removal, protect hwmon accesses to thermal zone operations
with the thermal zone mutex. After acquiring the mutex, ensure that the
thermal zone device is registered before proceeding.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/thermal/thermal_hwmon.c

index f53f4ceb6a5de010f3e7b229d75d605736830121..c594c42bea6da21953997473400db879b23419b5 100644 (file)
@@ -77,7 +77,15 @@ temp_crit_show(struct device *dev, struct device_attribute *attr, char *buf)
        int temperature;
        int ret;
 
-       ret = tz->ops->get_crit_temp(tz, &temperature);
+       mutex_lock(&tz->lock);
+
+       if (device_is_registered(&tz->device))
+               ret = tz->ops->get_crit_temp(tz, &temperature);
+       else
+               ret = -ENODEV;
+
+       mutex_unlock(&tz->lock);
+
        if (ret)
                return ret;