@@ -177,6 +177,15 @@ static bool acpi_thermal_trip_valid(struct acpi_thermal_trip *acpi_trip)
177177 return acpi_trip -> temp_dk != THERMAL_TEMP_INVALID ;
178178}
179179
180+ static int active_trip_index (struct acpi_thermal * tz ,
181+ struct acpi_thermal_trip * acpi_trip )
182+ {
183+ struct acpi_thermal_active * active ;
184+
185+ active = container_of (acpi_trip , struct acpi_thermal_active , trip );
186+ return active - tz -> trips .active ;
187+ }
188+
180189static long get_passive_temp (struct acpi_thermal * tz )
181190{
182191 unsigned long long tmp ;
@@ -213,21 +222,18 @@ static long get_active_temp(struct acpi_thermal *tz, int index)
213222}
214223
215224static void acpi_thermal_update_trip (struct acpi_thermal * tz ,
216- int index )
225+ const struct thermal_trip * trip )
217226{
218- struct acpi_thermal_trip * acpi_trip ;
219-
220- acpi_trip = index == ACPI_THERMAL_TRIP_PASSIVE ?
221- & tz -> trips .passive .trip : & tz -> trips .active [index ].trip ;
222- if (!acpi_thermal_trip_valid (acpi_trip ))
223- return ;
227+ struct acpi_thermal_trip * acpi_trip = trip -> priv ;
224228
225- if (index == ACPI_THERMAL_TRIP_PASSIVE ) {
229+ if (trip -> type == THERMAL_TRIP_PASSIVE ) {
226230 if (psv > 0 )
227231 return ;
228232
229233 acpi_trip -> temp_dk = get_passive_temp (tz );
230234 } else {
235+ int index = active_trip_index (tz , acpi_trip );
236+
231237 acpi_trip -> temp_dk = get_active_temp (tz , index );
232238 }
233239
@@ -264,31 +270,39 @@ static bool update_trip_devices(struct acpi_thermal *tz,
264270 return true;
265271}
266272
267- static void acpi_thermal_update_trip_devices (struct acpi_thermal * tz , int index )
273+ static void acpi_thermal_update_trip_devices (struct acpi_thermal * tz ,
274+ const struct thermal_trip * trip )
268275{
269- struct acpi_thermal_trip * acpi_trip ;
270-
271- acpi_trip = index == ACPI_THERMAL_TRIP_PASSIVE ?
272- & tz -> trips .passive .trip : & tz -> trips .active [index ].trip ;
273- if (!acpi_thermal_trip_valid (acpi_trip ))
274- return ;
276+ struct acpi_thermal_trip * acpi_trip = trip -> priv ;
277+ int index = trip -> type == THERMAL_TRIP_PASSIVE ?
278+ ACPI_THERMAL_TRIP_PASSIVE : active_trip_index (tz , acpi_trip );
275279
276- if (update_trip_devices (tz , acpi_trip , index , true)) {
280+ if (update_trip_devices (tz , acpi_trip , index , true))
277281 return ;
278- }
279282
280283 acpi_trip -> temp_dk = THERMAL_TEMP_INVALID ;
281284 ACPI_THERMAL_TRIPS_EXCEPTION (tz , "state" );
282285}
283286
287+ struct adjust_trip_data {
288+ struct acpi_thermal * tz ;
289+ u32 event ;
290+ };
291+
284292static int acpi_thermal_adjust_trip (struct thermal_trip * trip , void * data )
285293{
286294 struct acpi_thermal_trip * acpi_trip = trip -> priv ;
287- struct acpi_thermal * tz = data ;
295+ struct adjust_trip_data * atd = data ;
296+ struct acpi_thermal * tz = atd -> tz ;
288297
289- if (!acpi_trip )
298+ if (!acpi_trip || ! acpi_thermal_trip_valid ( acpi_trip ) )
290299 return 0 ;
291300
301+ if (atd -> event == ACPI_THERMAL_NOTIFY_THRESHOLDS )
302+ acpi_thermal_update_trip (tz , trip );
303+ else
304+ acpi_thermal_update_trip_devices (tz , trip );
305+
292306 if (acpi_thermal_trip_valid (acpi_trip ))
293307 trip -> temperature = acpi_thermal_temp (tz , acpi_trip -> temp_dk );
294308 else
@@ -297,25 +311,6 @@ static int acpi_thermal_adjust_trip(struct thermal_trip *trip, void *data)
297311 return 0 ;
298312}
299313
300- static void acpi_thermal_adjust_thermal_zone (struct thermal_zone_device * thermal ,
301- unsigned long data )
302- {
303- struct acpi_thermal * tz = thermal_zone_device_priv (thermal );
304- int i ;
305-
306- if (data == ACPI_THERMAL_NOTIFY_THRESHOLDS ) {
307- acpi_thermal_update_trip (tz , ACPI_THERMAL_TRIP_PASSIVE );
308- for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ )
309- acpi_thermal_update_trip (tz , i );
310- } else {
311- acpi_thermal_update_trip_devices (tz , ACPI_THERMAL_TRIP_PASSIVE );
312- for (i = 0 ; i < ACPI_THERMAL_MAX_ACTIVE ; i ++ )
313- acpi_thermal_update_trip_devices (tz , i );
314- }
315-
316- for_each_thermal_trip (tz -> thermal_zone , acpi_thermal_adjust_trip , tz );
317- }
318-
319314static void acpi_queue_thermal_check (struct acpi_thermal * tz )
320315{
321316 if (!work_pending (& tz -> thermal_check_work ))
@@ -324,17 +319,18 @@ static void acpi_queue_thermal_check(struct acpi_thermal *tz)
324319
325320static void acpi_thermal_trips_update (struct acpi_thermal * tz , u32 event )
326321{
322+ struct adjust_trip_data atd = { .tz = tz , .event = event };
327323 struct acpi_device * adev = tz -> device ;
328324
329325 /*
330- * Use thermal_zone_device_exec () to carry out the trip points
326+ * Use thermal_zone_for_each_trip () to carry out the trip points
331327 * update, so as to protect thermal_get_trend() from getting stale
332328 * trip point temperatures and to prevent thermal_zone_device_update()
333329 * invoked from acpi_thermal_check_fn() from producing inconsistent
334330 * results.
335331 */
336- thermal_zone_device_exec (tz -> thermal_zone ,
337- acpi_thermal_adjust_thermal_zone , event );
332+ thermal_zone_for_each_trip (tz -> thermal_zone ,
333+ acpi_thermal_adjust_trip , & atd );
338334 acpi_queue_thermal_check (tz );
339335 acpi_bus_generate_netlink_event (adev -> pnp .device_class ,
340336 dev_name (& adev -> dev ), event , 0 );
0 commit comments