[v2,1/6] thermal: trip: Simplify computing trip indices

Message ID 4882956.31r3eYUQgx@kreacher
State New
Headers
Series thermal: core: Pass trip pointers to governor .throttle() callbacks |

Commit Message

Rafael J. Wysocki Oct. 12, 2023, 6:25 p.m. UTC
  From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

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>
---

v1 -> v2: Rebase on top of current linux-next

---
 drivers/thermal/thermal_trip.c |   13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
  

Comments

Daniel Lezcano Oct. 12, 2023, 9:15 p.m. UTC | #1
On 12/10/2023 20:25, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> 
> 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>
  

Patch

Index: linux-pm/drivers/thermal/thermal_trip.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_trip.c
+++ linux-pm/drivers/thermal/thermal_trip.c
@@ -173,12 +173,9 @@  int thermal_zone_set_trip(struct thermal
 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;
 }