summaryrefslogtreecommitdiff
path: root/drivers/thermal
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2024-08-19 17:51:36 +0200
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2024-08-22 17:43:14 +0200
commitb4e6d39817312919f907da266de202a30a7bc43b (patch)
tree3868177aa3ac92f6a1789bed5b993425ca68abc6 /drivers/thermal
parenta8bbe6f10f78f85243ff821432c5d798a6d99ed4 (diff)
thermal: core: Rearrange checks in thermal_bind_cdev_to_trip()
It is not necessary to look up the thermal zone and the cooling device in the respective global lists to check whether or not they are registered. It is sufficient to check whether or not their respective list nodes are empty for this purpose. Use the above observation to simplify thermal_bind_cdev_to_trip(). In addition, eliminate an unnecessary ternary operator from it. Moreover, add lockdep_assert_held() for thermal_list_lock to it because that lock must be held by its callers when it is running. 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/3324214.44csPzL39Z@rjwysocki.net
Diffstat (limited to 'drivers/thermal')
-rw-r--r--drivers/thermal/thermal_core.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c
index eb6769320006..903971f8f08c 100644
--- a/drivers/thermal/thermal_core.c
+++ b/drivers/thermal/thermal_core.c
@@ -789,25 +789,17 @@ int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz,
{
struct thermal_instance *dev;
struct thermal_instance *pos;
- struct thermal_zone_device *pos1;
- struct thermal_cooling_device *pos2;
bool upper_no_limit;
int result;
- list_for_each_entry(pos1, &thermal_tz_list, node) {
- if (pos1 == tz)
- break;
- }
- list_for_each_entry(pos2, &thermal_cdev_list, node) {
- if (pos2 == cdev)
- break;
- }
+ lockdep_assert_held(&thermal_list_lock);
- if (tz != pos1 || cdev != pos2)
+ if (list_empty(&tz->node) || list_empty(&cdev->node))
return -EINVAL;
/* lower default 0, upper default max_state */
- lower = lower == THERMAL_NO_LIMIT ? 0 : lower;
+ if (lower == THERMAL_NO_LIMIT)
+ lower = 0;
if (upper == THERMAL_NO_LIMIT) {
upper = cdev->max_state;