thermal: trip: Define for_each_trip() macro
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 12 Oct 2023 18:26:46 +0000 (20:26 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 20 Oct 2023 17:26:01 +0000 (19:26 +0200)
Define a new macro for_each_trip() to be used by the thermal core code
and thermal governors for walking trips in a given thermal zone.

Modify for_each_thermal_trip() to use this macro instead of an open-
coded loop over trips.

No intentional functional impact.

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>
drivers/thermal/thermal_core.h
drivers/thermal/thermal_trip.c

index 024e82ebf5920f109a0a29dd07b9ab627259f52d..4702d3a152f908f521e6d2598a281aa85c2140eb 100644 (file)
@@ -116,6 +116,9 @@ void __thermal_zone_device_update(struct thermal_zone_device *tz,
                                  enum thermal_notify_event event);
 
 /* Helpers */
+#define for_each_trip(__tz, __trip)    \
+       for (__trip = __tz->trips; __trip - __tz->trips < __tz->num_trips; __trip++)
+
 void __thermal_zone_set_trips(struct thermal_zone_device *tz);
 int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id,
                            struct thermal_trip *trip);
index 6dff0dae6ef693b957c72158f26b772eeb308d3f..9e07535d99bb40a5d95d11a673caf978426b48b3 100644 (file)
@@ -13,10 +13,11 @@ int for_each_thermal_trip(struct thermal_zone_device *tz,
                          int (*cb)(struct thermal_trip *, void *),
                          void *data)
 {
-       int i, ret;
+       struct thermal_trip *trip;
+       int ret;
 
-       for (i = 0; i < tz->num_trips; i++) {
-               ret = cb(&tz->trips[i], data);
+       for_each_trip(tz, trip) {
+               ret = cb(trip, data);
                if (ret)
                        return ret;
        }