summaryrefslogtreecommitdiff
path: root/drivers/thermal
diff options
context:
space:
mode:
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>2024-01-15 20:55:13 +0300
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2024-01-29 17:37:56 +0300
commitf2675e588f928f7f3051765563a18f90332bd57b (patch)
tree8c5c6847bd0cf09fde824562f72b3dda4f5dca7f /drivers/thermal
parentc6a783be82c893c6f124a5853bef2edeaf26dadf (diff)
downloadlinux-f2675e588f928f7f3051765563a18f90332bd57b.tar.xz
thermal: gov_fair_share: Fix dependency on trip points ordering
The computation in the fair share governor's get_trip_level() function currently works under the assumption that the temperature ordering of trips[] in a thermal zone is ascending, which need not be the case. However, get_trip_level() can be made work regardless of whether or not the trips table is ordered by temperature in any way, so change it accordingly. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/thermal')
-rw-r--r--drivers/thermal/gov_fair_share.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/drivers/thermal/gov_fair_share.c b/drivers/thermal/gov_fair_share.c
index 538abb7de4e2..4da25a0009d7 100644
--- a/drivers/thermal/gov_fair_share.c
+++ b/drivers/thermal/gov_fair_share.c
@@ -18,22 +18,24 @@
static int get_trip_level(struct thermal_zone_device *tz)
{
const struct thermal_trip *trip, *level_trip = NULL;
- int trip_level;
+ int trip_level = -1;
for_each_trip(tz, trip) {
if (trip->temperature >= tz->temperature)
- break;
+ continue;
+
+ trip_level++;
- level_trip = trip;
+ if (!level_trip || trip->temperature > level_trip->temperature)
+ level_trip = trip;
}
/* Bail out if the temperature is not greater than any trips. */
- if (!level_trip)
+ if (trip_level < 0)
return 0;
- trip_level = thermal_zone_trip_id(tz, level_trip);
-
- trace_thermal_zone_trip(tz, trip_level, level_trip->type);
+ trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, level_trip),
+ level_trip->type);
return trip_level;
}