diff options
author | Hans de Goede <hdegoede@redhat.com> | 2023-05-10 18:22:32 +0200 |
---|---|---|
committer | Lee Jones <lee@kernel.org> | 2023-05-25 12:16:30 +0100 |
commit | fa15d8c69238b352cc143cb9d8f2ca4594b94022 (patch) | |
tree | 0a42c9f755cdb1211c35242850fae5d79e78063a /include/linux/leds.h | |
parent | e298d8a38b2341865f9feb04591aabb109e8bb13 (diff) | |
download | linux-fa15d8c69238b352cc143cb9d8f2ca4594b94022.tar.gz linux-fa15d8c69238b352cc143cb9d8f2ca4594b94022.tar.bz2 linux-fa15d8c69238b352cc143cb9d8f2ca4594b94022.zip |
leds: Fix set_brightness_delayed() race
When a trigger wants to switch from blinking to LED on it needs to call:
led_set_brightness(LED_OFF);
led_set_brightness(LED_FULL);
To first call disables blinking and the second then turns the LED on
(the power-supply charging-blink-full-solid triggers do this).
These calls happen immediately after each other, so it is possible
that set_brightness_delayed() from the first call has not run yet
when the led_set_brightness(LED_FULL) call finishes.
If this race hits then this is causing problems for both
sw- and hw-blinking:
For sw-blinking set_brightness_delayed() clears delayed_set_value
when LED_BLINK_DISABLE is set causing the led_set_brightness(LED_FULL)
call effects to get lost when hitting the race, resulting in the LED
turning off instead of on.
For hw-blinking if the race hits delayed_set_value has been
set to LED_FULL by the time set_brightness_delayed() runs.
So led_cdev->brightness_set_blocking() is never called with
LED_OFF as argument and the hw-blinking is never disabled leaving
the LED blinking instead of on.
Fix both issues by adding LED_SET_BRIGHTNESS and LED_SET_BRIGHTNESS_OFF
work_flags making this 2 separate actions to be run by
set_brightness_delayed().
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
Tested-by: Yauhen Kharuzhy <jekhor@gmail.com>
Link: https://lore.kernel.org/r/20230510162234.291439-3-hdegoede@redhat.com
Signed-off-by: Lee Jones <lee@kernel.org>
Diffstat (limited to 'include/linux/leds.h')
-rw-r--r-- | include/linux/leds.h | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/include/linux/leds.h b/include/linux/leds.h index c3dc22d184e2..de813fe96a20 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h @@ -124,6 +124,9 @@ struct led_classdev { #define LED_BLINK_INVERT 3 #define LED_BLINK_BRIGHTNESS_CHANGE 4 #define LED_BLINK_DISABLE 5 + /* Brightness off also disables hw-blinking so it is a separate action */ +#define LED_SET_BRIGHTNESS_OFF 6 +#define LED_SET_BRIGHTNESS 7 /* Set LED brightness level * Must not sleep. Use brightness_set_blocking for drivers |