2023-10-06 17:52:02

by Rafael J. Wysocki

[permalink] [raw]
Subject: [PATCH v1 2/6] thermal: trip: Define for_each_trip() macro

From: Rafael J. Wysocki <[email protected]>

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 <[email protected]>
---
drivers/thermal/thermal_core.h | 3 +++
drivers/thermal/thermal_trip.c | 7 ++++---
2 files changed, 7 insertions(+), 3 deletions(-)

Index: linux-pm/drivers/thermal/thermal_core.h
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_core.h
+++ linux-pm/drivers/thermal/thermal_core.h
@@ -116,6 +116,9 @@ void __thermal_zone_device_update(struct
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: linux-pm/drivers/thermal/thermal_trip.c
===================================================================
--- linux-pm.orig/drivers/thermal/thermal_trip.c
+++ linux-pm/drivers/thermal/thermal_trip.c
@@ -13,12 +13,13 @@ int for_each_thermal_trip(struct thermal
int (*cb)(struct thermal_trip *, void *),
void *data)
{
- int i, ret;
+ struct thermal_trip *trip;
+ int ret;

lockdep_assert_held(&tz->lock);

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




2023-10-12 14:45:04

by Daniel Lezcano

[permalink] [raw]
Subject: Re: [PATCH v1 2/6] thermal: trip: Define for_each_trip() macro

On 06/10/2023 19:41, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <[email protected]>
>
> 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 <[email protected]>

Acked-by: Daniel Lezcano <[email protected]>

--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog

2023-10-20 17:14:24

by Lukasz Luba

[permalink] [raw]
Subject: Re: [PATCH v1 2/6] thermal: trip: Define for_each_trip() macro



On 10/6/23 18:41, Rafael J. Wysocki wrote:
> From: Rafael J. Wysocki <[email protected]>
>
> 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 <[email protected]>
> ---
> drivers/thermal/thermal_core.h | 3 +++
> drivers/thermal/thermal_trip.c | 7 ++++---
> 2 files changed, 7 insertions(+), 3 deletions(-)
>
> Index: linux-pm/drivers/thermal/thermal_core.h
> ===================================================================
> --- linux-pm.orig/drivers/thermal/thermal_core.h
> +++ linux-pm/drivers/thermal/thermal_core.h
> @@ -116,6 +116,9 @@ void __thermal_zone_device_update(struct
> 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: linux-pm/drivers/thermal/thermal_trip.c
> ===================================================================
> --- linux-pm.orig/drivers/thermal/thermal_trip.c
> +++ linux-pm/drivers/thermal/thermal_trip.c
> @@ -13,12 +13,13 @@ int for_each_thermal_trip(struct thermal
> int (*cb)(struct thermal_trip *, void *),
> void *data)
> {
> - int i, ret;
> + struct thermal_trip *trip;
> + int ret;
>
> lockdep_assert_held(&tz->lock);
>
> - 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;
> }
>
>
>

LGTM

Reviewed-by: Lukasz Luba <[email protected]>

2023-10-20 17:19:35

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [PATCH v1 2/6] thermal: trip: Define for_each_trip() macro

On Fri, Oct 20, 2023 at 7:14 PM Lukasz Luba <[email protected]> wrote:
>
>
>
> On 10/6/23 18:41, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <[email protected]>
> >
> > 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 <[email protected]>
> > ---
> > drivers/thermal/thermal_core.h | 3 +++
> > drivers/thermal/thermal_trip.c | 7 ++++---
> > 2 files changed, 7 insertions(+), 3 deletions(-)
> >
> > Index: linux-pm/drivers/thermal/thermal_core.h
> > ===================================================================
> > --- linux-pm.orig/drivers/thermal/thermal_core.h
> > +++ linux-pm/drivers/thermal/thermal_core.h
> > @@ -116,6 +116,9 @@ void __thermal_zone_device_update(struct
> > 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: linux-pm/drivers/thermal/thermal_trip.c
> > ===================================================================
> > --- linux-pm.orig/drivers/thermal/thermal_trip.c
> > +++ linux-pm/drivers/thermal/thermal_trip.c
> > @@ -13,12 +13,13 @@ int for_each_thermal_trip(struct thermal
> > int (*cb)(struct thermal_trip *, void *),
> > void *data)
> > {
> > - int i, ret;
> > + struct thermal_trip *trip;
> > + int ret;
> >
> > lockdep_assert_held(&tz->lock);
> >
> > - 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;
> > }
> >
> >
> >
>
> LGTM
>
> Reviewed-by: Lukasz Luba <[email protected]>

Thanks!