Skip to contentSkip to conversation

leds: Ensure hardware blinking turns off when requested

PATCH In review Eddie James 2 participants 4 messages May 20, 2022 – Apr 5, 2023 LED

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds: Ensure hardware blinking turns off when requested

If an LED is blinking through the hardware and the trigger is deactivated, the driver will set the brightness to 0 to disable blinking. However, if the LED driver doesn't support non-blocking operations, the request for setting brightness to 0 will get queued. Then if a user requests a new non-zero brightness before the request for 0 brightness is executed, the LED blinking will not get disabled since the brightness will simply be updated.
Fix this by flushing the workqueue before updating the requested brightness.

Fixes 4d71a4a12b13 ("leds: Add support for setting brightness in a synchronous way")
---
 drivers/leds/led-class.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/leds/led-class.c +2 -0
index 6a8ea94834fa..861a1cb5df5b 100644
@@ -55,6 +55,8 @@ static ssize_t brightness_store(struct device *dev,
 
 	if (state == LED_OFF)
 		led_trigger_remove(led_cdev);
+	/* flush out any request to disable blinking */
+	flush_work(&led_cdev->set_brightness_work);
 	led_set_brightness(led_cdev, state);
 	flush_work(&led_cdev->set_brightness_work);
 
Signature · 1 line
2.27.0
#1 lore raw

Any update on this?

Thanks,

Eddie

Quoted 29 lines · Eddie James

If an LED is blinking through the hardware and the trigger is deactivated, the driver will set the brightness to 0 to disable blinking. However, if the LED driver doesn't support non-blocking operations, the request for setting brightness to 0 will get queued. Then if a user requests a new non-zero brightness before the request for 0 brightness is executed, the LED blinking will not get disabled since the brightness will simply be updated.
Fix this by flushing the workqueue before updating the requested brightness.

Fixes 4d71a4a12b13 ("leds: Add support for setting brightness in a synchronous way")
---
  drivers/leds/led-class.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/leds/led-class.c +2 -0
index 6a8ea94834fa..861a1cb5df5b 100644
@@ -55,6 +55,8 @@ static ssize_t brightness_store(struct device *dev,
 
  	if (state == LED_OFF)
  		led_trigger_remove(led_cdev);
+	/* flush out any request to disable blinking */
+	flush_work(&led_cdev->set_brightness_work);
  	led_set_brightness(led_cdev, state);
  	flush_work(&led_cdev->set_brightness_work);
 
#2 lore raw
In reply to Eddie James
Quoted 9 lines · Eddie James

If an LED is blinking through the hardware and the trigger is deactivated, the driver will set the brightness to 0 to disable blinking. However, if the LED driver doesn't support non-blocking operations, the request for setting brightness to 0 will get queued. Then if a user requests a new non-zero brightness before the request for 0 brightness is executed, the LED blinking will not get disabled since the brightness will simply be updated.
Fix this by flushing the workqueue before updating the requested brightness.

I just realized this never made it anywhere. Pavel, any thoughts?

Thanks,

Eddie

Quoted 20 lines
Fixes 4d71a4a12b13 ("leds: Add support for setting brightness in a synchronous way")
---
  drivers/leds/led-class.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/leds/led-class.c +2 -0
index 6a8ea94834fa..861a1cb5df5b 100644
@@ -55,6 +55,8 @@ static ssize_t brightness_store(struct device *dev,
 
  	if (state == LED_OFF)
  		led_trigger_remove(led_cdev);
+	/* flush out any request to disable blinking */
+	flush_work(&led_cdev->set_brightness_work);
  	led_set_brightness(led_cdev, state);
  	flush_work(&led_cdev->set_brightness_work);
 
maintainer
#3 lore raw

Apologies for any chaos this may cause, I'm replying from Gmail since this doesn't appear to be in my inbox.

Quoted 14 lines · Eddie James
Quoted 9 lines · Eddie James

If an LED is blinking through the hardware and the trigger is deactivated, the driver will set the brightness to 0 to disable blinking. However, if the LED driver doesn't support non-blocking operations, the request for setting brightness to 0 will get queued. Then if a user requests a new non-zero brightness before the request for 0 brightness is executed, the LED blinking will not get disabled since the brightness will simply be updated.
Fix this by flushing the workqueue before updating the requested brightness.

Quoted 1 line

I just realized this never made it anywhere. Pavel, any thoughts?

Submit a [RESEND] please.

Also, please ensure you re-run get_maintainer.pl before doing so.

Quoted 19 lines
Quoted 19 lines
Fixes 4d71a4a12b13 ("leds: Add support for setting brightness in a synchronous way")
---
  drivers/leds/led-class.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/leds/led-class.c +2 -0
index 6a8ea94834fa..861a1cb5df5b 100644
@@ -55,6 +55,8 @@ static ssize_t brightness_store(struct device *dev,
 
      if (state == LED_OFF)
              led_trigger_remove(led_cdev);
+     /* flush out any request to disable blinking */
+     flush_work(&led_cdev->set_brightness_work);
      led_set_brightness(led_cdev, state);
      flush_work(&led_cdev->set_brightness_work);