thermal: trip: Simplify computing trip indices
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 12 Oct 2023 18:25:06 +0000 (20:25 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 20 Oct 2023 17:25:22 +0000 (19:25 +0200)
A trip index can be computed right away as a difference between the
value of a trip pointer pointing to the given trip object and the
start of the trips[] table in the given thermal zone, so change
thermal_zone_trip_id() accordingly.

No intentional functional impact (except for some speedup).

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Reviewed-by: Lukasz Luba <lukasz.luba@arm.com>
Tested-by: Lukasz Luba <lukasz.luba@arm.com>
drivers/thermal/thermal_trip.c

index 80f3cdb2f30ee8c3e589697b9e85d38f52a8925d..6dff0dae6ef693b957c72158f26b772eeb308d3f 100644 (file)
@@ -173,12 +173,9 @@ int thermal_zone_set_trip(struct thermal_zone_device *tz, int trip_id,
 int thermal_zone_trip_id(struct thermal_zone_device *tz,
                         const struct thermal_trip *trip)
 {
-       int i;
-
-       for (i = 0; i < tz->num_trips; i++) {
-               if (&tz->trips[i] == trip)
-                       return i;
-       }
-
-       return -ENODATA;
+       /*
+        * Assume the trip to be located within the bounds of the thermal
+        * zone's trips[] table.
+        */
+       return trip - tz->trips;
 }