Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: triggers: Flush pending brightness before activating trigger

The race fixed in timer_trig_activate() between a blocking
set_brightness() call and trigger->activate() can affect any trigger.
So move the call to flush_work() into led_trigger_set() where it can
avoid the race for all triggers.

Fixes: 0db37915d912 ("leds: avoid races with workqueue")
Fixes: 8c0f693c6eff ("leds: avoid flush_work in atomic context")
Cc: stable@vger.kernel.org
Tested-by: Dustin L. Howett <dustin@howett.net>
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20240613-led-trigger-flush-v2-1-f4f970799d77@weissschuh.net
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Thomas Weißschuh and committed by
Lee Jones
ab477b76 25458b2a

+6 -5
+6
drivers/leds/led-triggers.c
··· 201 201 */ 202 202 synchronize_rcu(); 203 203 204 + /* 205 + * If "set brightness to 0" is pending in workqueue, 206 + * we don't want that to be reordered after ->activate() 207 + */ 208 + flush_work(&led_cdev->set_brightness_work); 209 + 204 210 ret = 0; 205 211 if (trig->activate) 206 212 ret = trig->activate(led_cdev);
-5
drivers/leds/trigger/ledtrig-timer.c
··· 110 110 led_cdev->flags &= ~LED_INIT_DEFAULT_TRIGGER; 111 111 } 112 112 113 - /* 114 - * If "set brightness to 0" is pending in workqueue, we don't 115 - * want that to be reordered after blink_set() 116 - */ 117 - flush_work(&led_cdev->set_brightness_work); 118 113 led_blink_set(led_cdev, &led_cdev->blink_delay_on, 119 114 &led_cdev->blink_delay_off); 120 115