OSDN Git Service

thermal/core: Rework the monitoring a bit
authorDaniel Lezcano <daniel.lezcano@linaro.org>
Fri, 5 Aug 2022 15:38:31 +0000 (17:38 +0200)
committerDaniel Lezcano <daniel.lezcano@linaro.org>
Wed, 17 Aug 2022 12:09:39 +0000 (14:09 +0200)
commit15a73839e3ced8d418e6c34548f5e2789f9da619
treea95917ee596347ecaa1ecb7d4b9455bbe22a0036
parent9662756a9a1c34b3ee606dcddfda6a457f89b07f
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 <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20220805153834.2510142-2-daniel.lezcano@linaro.org
drivers/thermal/thermal_core.c