Skip to content

Commit cd3c00e

Browse files
committed
thermal: int340x: Use thermal_zone_for_each_trip()
Modify int340x_thermal_update_trips() to use thermal_zone_for_each_trip() for walking trips instead of using the trips[] table passed to the thermal zone registration function. For this purpose, store active trip point indices in the priv fieids of the corresponding thermal_trip structures. No intentional functional impact. Signed-off-by: Rafael J. Wysocki <[email protected]> Acked-by: Daniel Lezcano <[email protected]>
1 parent 2cbe1a3 commit cd3c00e

File tree

1 file changed

+42
-36
lines changed

1 file changed

+42
-36
lines changed

drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ static struct thermal_zone_device_ops int340x_thermal_zone_ops = {
6767
.critical = int340x_thermal_critical,
6868
};
6969

70+
static inline void *int_to_trip_priv(int i)
71+
{
72+
return (void *)(long)i;
73+
}
74+
75+
static inline int trip_priv_to_int(const struct thermal_trip *trip)
76+
{
77+
return (long)trip->priv;
78+
}
79+
7080
static int int340x_thermal_read_trips(struct acpi_device *zone_adev,
7181
struct thermal_trip *zone_trips,
7282
int trip_cnt)
@@ -101,6 +111,7 @@ static int int340x_thermal_read_trips(struct acpi_device *zone_adev,
101111
break;
102112

103113
zone_trips[trip_cnt].type = THERMAL_TRIP_ACTIVE;
114+
zone_trips[trip_cnt].priv = int_to_trip_priv(i);
104115
trip_cnt++;
105116
}
106117

@@ -212,45 +223,40 @@ void int340x_thermal_zone_remove(struct int34x_thermal_zone *int34x_zone)
212223
}
213224
EXPORT_SYMBOL_GPL(int340x_thermal_zone_remove);
214225

215-
void int340x_thermal_update_trips(struct int34x_thermal_zone *int34x_zone)
226+
static int int340x_update_one_trip(struct thermal_trip *trip, void *arg)
216227
{
217-
struct acpi_device *zone_adev = int34x_zone->adev;
218-
struct thermal_trip *zone_trips = int34x_zone->trips;
219-
int trip_cnt = int34x_zone->zone->num_trips;
220-
int act_trip_nr = 0;
221-
int i;
222-
223-
mutex_lock(&int34x_zone->zone->lock);
224-
225-
for (i = int34x_zone->aux_trip_nr; i < trip_cnt; i++) {
226-
int temp, err;
227-
228-
switch (zone_trips[i].type) {
229-
case THERMAL_TRIP_CRITICAL:
230-
err = thermal_acpi_critical_trip_temp(zone_adev, &temp);
231-
break;
232-
case THERMAL_TRIP_HOT:
233-
err = thermal_acpi_hot_trip_temp(zone_adev, &temp);
234-
break;
235-
case THERMAL_TRIP_PASSIVE:
236-
err = thermal_acpi_passive_trip_temp(zone_adev, &temp);
237-
break;
238-
case THERMAL_TRIP_ACTIVE:
239-
err = thermal_acpi_active_trip_temp(zone_adev, act_trip_nr++,
240-
&temp);
241-
break;
242-
default:
243-
err = -ENODEV;
244-
}
245-
if (err) {
246-
zone_trips[i].temperature = THERMAL_TEMP_INVALID;
247-
continue;
248-
}
249-
250-
zone_trips[i].temperature = temp;
228+
struct acpi_device *zone_adev = arg;
229+
int temp, err;
230+
231+
switch (trip->type) {
232+
case THERMAL_TRIP_CRITICAL:
233+
err = thermal_acpi_critical_trip_temp(zone_adev, &temp);
234+
break;
235+
case THERMAL_TRIP_HOT:
236+
err = thermal_acpi_hot_trip_temp(zone_adev, &temp);
237+
break;
238+
case THERMAL_TRIP_PASSIVE:
239+
err = thermal_acpi_passive_trip_temp(zone_adev, &temp);
240+
break;
241+
case THERMAL_TRIP_ACTIVE:
242+
err = thermal_acpi_active_trip_temp(zone_adev,
243+
trip_priv_to_int(trip),
244+
&temp);
245+
break;
246+
default:
247+
err = -ENODEV;
251248
}
249+
if (err)
250+
temp = THERMAL_TEMP_INVALID;
252251

253-
mutex_unlock(&int34x_zone->zone->lock);
252+
trip->temperature = temp;
253+
return 0;
254+
}
255+
256+
void int340x_thermal_update_trips(struct int34x_thermal_zone *int34x_zone)
257+
{
258+
thermal_zone_for_each_trip(int34x_zone->zone, int340x_update_one_trip,
259+
int34x_zone->adev);
254260
}
255261
EXPORT_SYMBOL_GPL(int340x_thermal_update_trips);
256262

0 commit comments

Comments
 (0)