summaryrefslogtreecommitdiffstats
path: root/drivers/thermal
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2024-08-19 17:58:27 +0200
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2024-08-22 17:43:14 +0200
commitd48005511a5496defa8ff6828ce9fdd1fb4dcd86 (patch)
treee7556bfd4a779ec999091bd4d3236dfdb865430e /drivers/thermal
parentthermal: sysfs: Use the dev argument in instance-related show/store (diff)
downloadlinux-d48005511a5496defa8ff6828ce9fdd1fb4dcd86.tar.xz
linux-d48005511a5496defa8ff6828ce9fdd1fb4dcd86.zip
thermal: core: Move thermal zone locking out of bind/unbind functions
Since thermal_bind_cdev_to_trip() and thermal_unbind_cdev_from_trip() acquire the thermal zone lock, the locking rules for their callers get complicated. In particular, the thermal zone lock cannot be acquired in any code path leading to one of these functions even though it might be useful to do so. To address this, remove the thermal zone locking from both these functions, add lockdep assertions for the thermal zone lock to both of them and make their callers acquire the thermal zone lock instead. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Zhang Rui <rui.zhang@intel.com> Reviewed-by: Daniel Lezcano <daniel.lezcano@linaro.org> Link: https://patch.msgid.link/3837835.kQq0lBPeGt@rjwysocki.net
Diffstat (limited to 'drivers/thermal')
-rw-r--r--drivers/thermal/thermal_core.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index 0085a8df8523..6980d750e926 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -793,6 +793,7 @@ int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
int result;
lockdep_assert_held(&thermal_list_lock);
+ lockdep_assert_held(&tz->lock);
if (list_empty(&tz->node) || list_empty(&cdev->node))
return -EINVAL;
@@ -855,7 +856,6 @@ int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
if (result)
goto remove_trip_file;
- mutex_lock(&tz->lock);
mutex_lock(&cdev->lock);
list_for_each_entry(pos, &tz->thermal_instances, tz_node)
if (pos->trip == trip && pos->cdev == cdev) {
@@ -870,7 +870,6 @@ int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
thermal_governor_update_tz(tz, THERMAL_TZ_BIND_CDEV);
}
mutex_unlock(&cdev->lock);
- mutex_unlock(&tz->lock);
if (!result)
return 0;
@@ -894,11 +893,19 @@ int thermal_zone_bind_cooling_device(struct thermal_zone_device *tz,
unsigned long upper, unsigned long lower,
unsigned int weight)
{
+ int ret;
+
if (trip_index < 0 || trip_index >= tz->num_trips)
return -EINVAL;
- return thermal_bind_cdev_to_trip(tz, &tz->trips[trip_index].trip, cdev,
- upper, lower, weight);
+ mutex_lock(&tz->lock);
+
+ ret = thermal_bind_cdev_to_trip(tz, &tz->trips[trip_index].trip, cdev,
+ upper, lower, weight);
+
+ mutex_unlock(&tz->lock);
+
+ return ret;
}
EXPORT_SYMBOL_GPL(thermal_zone_bind_cooling_device);
@@ -920,7 +927,8 @@ int thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz,
{
struct thermal_instance *pos, *next;
- mutex_lock(&tz->lock);
+ lockdep_assert_held(&tz->lock);
+
mutex_lock(&cdev->lock);
list_for_each_entry_safe(pos, next, &tz->thermal_instances, tz_node) {
if (pos->trip == trip && pos->cdev == cdev) {
@@ -930,12 +938,10 @@ int thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz,
thermal_governor_update_tz(tz, THERMAL_TZ_UNBIND_CDEV);
mutex_unlock(&cdev->lock);
- mutex_unlock(&tz->lock);
goto unbind;
}
}
mutex_unlock(&cdev->lock);
- mutex_unlock(&tz->lock);
return -ENODEV;
@@ -953,10 +959,18 @@ int thermal_zone_unbind_cooling_device(struct thermal_zone_device *tz,
int trip_index,
struct thermal_cooling_device *cdev)
{
+ int ret;
+
if (trip_index < 0 || trip_index >= tz->num_trips)
return -EINVAL;
- return thermal_unbind_cdev_from_trip(tz, &tz->trips[trip_index].trip, cdev);
+ mutex_lock(&tz->lock);
+
+ ret = thermal_unbind_cdev_from_trip(tz, &tz->trips[trip_index].trip, cdev);
+
+ mutex_unlock(&tz->lock);
+
+ return ret;
}
EXPORT_SYMBOL_GPL(thermal_zone_unbind_cooling_device);