linux-leds.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: triggers: flush pending brightness before activating trigger
@ 2024-06-03 21:45 Thomas Weißschuh
  2024-06-04 16:46 ` Dustin Howett
  2024-06-13 15:02 ` Lee Jones
  0 siblings, 2 replies; 3+ messages in thread
From: Thomas Weißschuh @ 2024-06-03 21:45 UTC (permalink / raw)
  To: Pavel Machek, Lee Jones, Jacek Anaszewski
  Cc: linux-leds, linux-kernel, Dustin Howett, Thomas Weißschuh

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")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
Dustin, could you validate that this fixes the issue you encountered in
the cros_ec led driver?
---
 drivers/leds/led-triggers.c          | 10 ++++++++--
 drivers/leds/trigger/ledtrig-timer.c |  5 -----
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index b1b323b19301..9e6233dbcfd4 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -195,10 +195,16 @@ int led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
 		led_cdev->trigger = trig;
 
 		ret = 0;
-		if (trig->activate)
+		if (trig->activate) {
+			/*
+			 * If "set brightness to 0" is pending in workqueue,
+			 * we don't want that to be reordered after ->activate()
+			 */
+			flush_work(&led_cdev->set_brightness_work);
 			ret = trig->activate(led_cdev);
-		else
+		} else {
 			led_set_brightness(led_cdev, trig->brightness);
+		}
 		if (ret)
 			goto err_activate;
 
diff --git a/drivers/leds/trigger/ledtrig-timer.c b/drivers/leds/trigger/ledtrig-timer.c
index b4688d1d9d2b..1d213c999d40 100644
--- a/drivers/leds/trigger/ledtrig-timer.c
+++ b/drivers/leds/trigger/ledtrig-timer.c
@@ -110,11 +110,6 @@ static int timer_trig_activate(struct led_classdev *led_cdev)
 		led_cdev->flags &= ~LED_INIT_DEFAULT_TRIGGER;
 	}
 
-	/*
-	 * If "set brightness to 0" is pending in workqueue, we don't
-	 * want that to be reordered after blink_set()
-	 */
-	flush_work(&led_cdev->set_brightness_work);
 	led_blink_set(led_cdev, &led_cdev->blink_delay_on,
 		      &led_cdev->blink_delay_off);
 

---
base-commit: f06ce441457d4abc4d76be7acba26868a2d02b1c
change-id: 20240603-led-trigger-flush-3bef303eb902

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] leds: triggers: flush pending brightness before activating trigger
  2024-06-03 21:45 [PATCH] leds: triggers: flush pending brightness before activating trigger Thomas Weißschuh
@ 2024-06-04 16:46 ` Dustin Howett
  2024-06-13 15:02 ` Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Dustin Howett @ 2024-06-04 16:46 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Pavel Machek, Lee Jones, Jacek Anaszewski, linux-leds,
	linux-kernel

On Mon, Jun 3, 2024 at 4:45 PM Thomas Weißschuh <linux@weissschuh.net> wrote:
>
> Dustin, could you validate that this fixes the issue you encountered in
> the cros_ec led driver?

Thanks for the quick patch. Yes, it fixes the issue I encountered with
leds_cros_ec!

Tested-by: Dustin L. Howett <dustin@howett.net>

Cheers,
d

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] leds: triggers: flush pending brightness before activating trigger
  2024-06-03 21:45 [PATCH] leds: triggers: flush pending brightness before activating trigger Thomas Weißschuh
  2024-06-04 16:46 ` Dustin Howett
@ 2024-06-13 15:02 ` Lee Jones
  1 sibling, 0 replies; 3+ messages in thread
From: Lee Jones @ 2024-06-13 15:02 UTC (permalink / raw)
  To: Thomas Weißschuh
  Cc: Pavel Machek, Jacek Anaszewski, linux-leds, linux-kernel,
	Dustin Howett

On Mon, 03 Jun 2024, Thomas Weißschuh wrote:

> 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")
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> Dustin, could you validate that this fixes the issue you encountered in
> the cros_ec led driver?
> ---
>  drivers/leds/led-triggers.c          | 10 ++++++++--
>  drivers/leds/trigger/ledtrig-timer.c |  5 -----
>  2 files changed, 8 insertions(+), 7 deletions(-)

This patch clashes with:

  https://lore.kernel.org/all/20240531120124.75662-1-hdegoede@redhat.com/

Please rebase and ensure that your solution doesn't conflict.

-- 
Lee Jones [李琼斯]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-13 15:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-03 21:45 [PATCH] leds: triggers: flush pending brightness before activating trigger Thomas Weißschuh
2024-06-04 16:46 ` Dustin Howett
2024-06-13 15:02 ` Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).