summaryrefslogtreecommitdiff
path: root/drivers/thermal/thermal_core.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2022-11-10 18:25:00 +0300
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2022-11-14 21:04:37 +0300
commitb778b4d782d48b9a8751b21deb8eb2f054a3c772 (patch)
tree1b484f24cc78e9ea25c3ce26ac89358c93ce68f4 /drivers/thermal/thermal_core.c
parent91b3aafc2238a91051dff79a8d072a18c805ee50 (diff)
downloadlinux-b778b4d782d48b9a8751b21deb8eb2f054a3c772.tar.xz
thermal/core: Protect thermal device operations against thermal device removal
Thermal device operations may be called after thermal zone device removal. After thermal zone device removal, thermal zone device operations must no longer be called. To prevent such calls from happening, ensure that the thermal device is registered before executing any thermal device operations. Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/thermal/thermal_core.c')
-rw-r--r--drivers/thermal/thermal_core.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 173b049dca41..cc7dbcb2c739 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -203,6 +203,9 @@ int thermal_zone_device_set_policy(struct thermal_zone_device *tz,
mutex_lock(&thermal_governor_lock);
mutex_lock(&tz->lock);
+ if (!device_is_registered(&tz->device))
+ goto exit;
+
gov = __find_governor(strim(policy));
if (!gov)
goto exit;
@@ -445,6 +448,12 @@ static int thermal_zone_device_set_mode(struct thermal_zone_device *tz,
return ret;
}
+ if (!device_is_registered(&tz->device)) {
+ mutex_unlock(&tz->lock);
+
+ return -ENODEV;
+ }
+
if (tz->ops->change_mode)
ret = tz->ops->change_mode(tz, mode);
@@ -486,7 +495,8 @@ void thermal_zone_device_update(struct thermal_zone_device *tz,
enum thermal_notify_event event)
{
mutex_lock(&tz->lock);
- __thermal_zone_device_update(tz, event);
+ if (device_is_registered(&tz->device))
+ __thermal_zone_device_update(tz, event);
mutex_unlock(&tz->lock);
}
EXPORT_SYMBOL_GPL(thermal_zone_device_update);