• Daniel Lezcano's avatar
    thermal/core: Rework the monitoring a bit · 15a73839
    Daniel Lezcano authored
    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: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
    Link: https://lore.kernel.org/r/20220805153834.2510142-2-daniel.lezcano@linaro.org
    15a73839
thermal_core.c 38.3 KB