Skip to content

Commit 15a7383

Browse files
committed
thermal/core: Rework the monitoring a bit
The should_stop_polling() function wraps the function thermal_zone_device_is_enabled(). The monitor_thermal_zone() function checks if the thermal zone is enabled via the should_stop_polling() function. However, the instant after checking the thermal zone is enabled, this one can be disabled, so even if that reduces the race window, it does not prevent that and the monitoring can be set again with the thermal zone disabled. For this reason, the function should_stop_polling() is replaced by a direct check of the thermal zone mode with the mutex locks held, that prevents the situation described above. As the semantic is clear with the thermal_zone_is_enabled() function, we can remove the should_stop_polling() function and replace the check with the former function. While at it, reorder the checks to improve the readability of the monitor_thermal_zone() function. In the future, the thermal_zone_device_disable() and the thermal_zone_device_enable() functions should unset / set the polling timer directly instead of relying on the next thermal_zone_device_update() call to do that. That will make a synchronous thermal zone mode change but the locking scheme should be double checked for that which out of the scope of this change. Signed-off-by: Daniel Lezcano <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9662756 commit 15a7383

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

drivers/thermal/thermal_core.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -295,25 +295,16 @@ static void thermal_zone_device_set_polling(struct thermal_zone_device *tz,
295295
cancel_delayed_work(&tz->poll_queue);
296296
}
297297

298-
static inline bool should_stop_polling(struct thermal_zone_device *tz)
299-
{
300-
return !thermal_zone_device_is_enabled(tz);
301-
}
302-
303298
static void monitor_thermal_zone(struct thermal_zone_device *tz)
304299
{
305-
bool stop;
306-
307-
stop = should_stop_polling(tz);
308-
309300
mutex_lock(&tz->lock);
310301

311-
if (!stop && tz->passive)
302+
if (tz->mode != THERMAL_DEVICE_ENABLED)
303+
thermal_zone_device_set_polling(tz, 0);
304+
else if (tz->passive)
312305
thermal_zone_device_set_polling(tz, tz->passive_delay_jiffies);
313-
else if (!stop && tz->polling_delay_jiffies)
306+
else if (tz->polling_delay_jiffies)
314307
thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies);
315-
else
316-
thermal_zone_device_set_polling(tz, 0);
317308

318309
mutex_unlock(&tz->lock);
319310
}
@@ -480,7 +471,7 @@ void thermal_zone_device_update(struct thermal_zone_device *tz,
480471
{
481472
int count;
482473

483-
if (should_stop_polling(tz))
474+
if (!thermal_zone_device_is_enabled(tz))
484475
return;
485476

486477
if (atomic_read(&in_suspend))

0 commit comments

Comments
 (0)