]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
thermal: gov_fair_share: Fix dependency on trip points ordering
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 15 Jan 2024 17:55:13 +0000 (18:55 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 29 Jan 2024 14:37:56 +0000 (15:37 +0100)
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>
drivers/thermal/gov_fair_share.c

index 538abb7de4e2b1252376d343b81255bcbd33dfe8..4da25a0009d73dfc8e7a623880a0e2d955353a09 100644 (file)
 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;
 }