Re: [PATCH v1 1/6] thermal: trip: Simplify computing trip indices

From: Rafael J. Wysocki
Date: Thu Oct 12 2023 - 12:21:26 EST


On Thu, Oct 12, 2023 at 4:27 PM Daniel Lezcano
<daniel.lezcano@xxxxxxxxxx> wrote:
>
> On 06/10/2023 19:40, Rafael J. Wysocki wrote:
> > From: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
> >
> > 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 thermal zone containing the trip, so
> > change thermal_zone_trip_id() accordingly.
> >
> > No intentional functional impact (except for some speedup).
> >
> > Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
> > ---
> > drivers/thermal/thermal_trip.c | 13 +++++--------
> > 1 file changed, 5 insertions(+), 8 deletions(-)
> >
> > Index: linux-pm/drivers/thermal/thermal_trip.c
> > ===================================================================
> > --- linux-pm.orig/drivers/thermal/thermal_trip.c
> > +++ linux-pm/drivers/thermal/thermal_trip.c
> > @@ -175,14 +175,11 @@ int thermal_zone_set_trip(struct thermal
> > int thermal_zone_trip_id(struct thermal_zone_device *tz,
> > const struct thermal_trip *trip)
> > {
> > - int i;
> > -
> > lockdep_assert_held(&tz->lock);
> >
> > - 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;
>
> Shouldn't be divided by sizeof(*trip) ?

No, it's in sizeof(*trip) units already.