linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds: core: Use blocking op for system suspend
@ 2020-07-01  9:35 Kai-Heng Feng
  2020-07-01 21:28 ` Jacek Anaszewski
  0 siblings, 1 reply; 3+ messages in thread
From: Kai-Heng Feng @ 2020-07-01  9:35 UTC (permalink / raw)
  To: jacek.anaszewski, pavel
  Cc: anthony.wong, Kai-Heng Feng, Dan Murphy, open list:LED SUBSYSTEM,
	open list

Sometimes LED won't be turned off by LED_CORE_SUSPENDRESUME flag upon
system suspend.

led_set_brightness_nopm() uses schedule_work() to set LED brightness.
However, there's no guarantee that the scheduled work gets executed
because no one calls flush_scheduled_work().

As flush_scheduled_work() may affect other drivers' suspend routines,
take a more contained approach which uses blocking op to make sure the
LED gets turned off.

Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 drivers/leds/led-core.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
index f1f718dbe0f8..9a5bfcd7a704 100644
--- a/drivers/leds/led-core.c
+++ b/drivers/leds/led-core.c
@@ -269,6 +269,11 @@ EXPORT_SYMBOL_GPL(led_set_brightness);
 void led_set_brightness_nopm(struct led_classdev *led_cdev,
 			      enum led_brightness value)
 {
+
+	if (led_cdev->flags & LED_SUSPENDED &&
+	    !__led_set_brightness_blocking(led_cdev, value))
+		return;
+
 	/* Use brightness_set op if available, it is guaranteed not to sleep */
 	if (!__led_set_brightness(led_cdev, value))
 		return;
-- 
2.17.1


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

* Re: [PATCH] leds: core: Use blocking op for system suspend
  2020-07-01  9:35 [PATCH] leds: core: Use blocking op for system suspend Kai-Heng Feng
@ 2020-07-01 21:28 ` Jacek Anaszewski
  2020-07-02  5:20   ` Kai-Heng Feng
  0 siblings, 1 reply; 3+ messages in thread
From: Jacek Anaszewski @ 2020-07-01 21:28 UTC (permalink / raw)
  To: Kai-Heng Feng, pavel
  Cc: anthony.wong, Dan Murphy, open list:LED SUBSYSTEM, open list

Hi Kai-Heng,

Thank you for the patch.

On 7/1/20 11:35 AM, Kai-Heng Feng wrote:
> Sometimes LED won't be turned off by LED_CORE_SUSPENDRESUME flag upon
> system suspend.

Just out of curiosity - are you experiencing that on some hardware?

> led_set_brightness_nopm() uses schedule_work() to set LED brightness.
> However, there's no guarantee that the scheduled work gets executed
> because no one calls flush_scheduled_work().
> 
> As flush_scheduled_work() may affect other drivers' suspend routines,
> take a more contained approach which uses blocking op to make sure the
> LED gets turned off.
> 
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
>   drivers/leds/led-core.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
> index f1f718dbe0f8..9a5bfcd7a704 100644
> --- a/drivers/leds/led-core.c
> +++ b/drivers/leds/led-core.c
> @@ -269,6 +269,11 @@ EXPORT_SYMBOL_GPL(led_set_brightness);
>   void led_set_brightness_nopm(struct led_classdev *led_cdev,
>   			      enum led_brightness value)
>   {
> +
> +	if (led_cdev->flags & LED_SUSPENDED &&
> +	    !__led_set_brightness_blocking(led_cdev, value))
> +		return;
> +

This function is "nopm" for a reason - we do not make here any
pm management related operations.

Instead of that, please just add

flush_work(&led_cdev->set_brightness_work);

at the end of led_classdev_suspend()

in drivers/leds/led-class.c.

-- 
Best regards,
Jacek Anaszewski

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

* Re: [PATCH] leds: core: Use blocking op for system suspend
  2020-07-01 21:28 ` Jacek Anaszewski
@ 2020-07-02  5:20   ` Kai-Heng Feng
  0 siblings, 0 replies; 3+ messages in thread
From: Kai-Heng Feng @ 2020-07-02  5:20 UTC (permalink / raw)
  To: Jacek Anaszewski
  Cc: pavel, anthony.wong, Dan Murphy, open list:LED SUBSYSTEM, open list



> On Jul 2, 2020, at 05:28, Jacek Anaszewski <jacek.anaszewski@gmail.com> wrote:
> 
> Hi Kai-Heng,
> 
> Thank you for the patch.
> 
> On 7/1/20 11:35 AM, Kai-Heng Feng wrote:
>> Sometimes LED won't be turned off by LED_CORE_SUSPENDRESUME flag upon
>> system suspend.
> 
> Just out of curiosity - are you experiencing that on some hardware?

Yes, mute and micmute LED on laptops sometimes are still on during suspend-to-idle.

> 
>> led_set_brightness_nopm() uses schedule_work() to set LED brightness.
>> However, there's no guarantee that the scheduled work gets executed
>> because no one calls flush_scheduled_work().
>> As flush_scheduled_work() may affect other drivers' suspend routines,
>> take a more contained approach which uses blocking op to make sure the
>> LED gets turned off.
>> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
>> ---
>>  drivers/leds/led-core.c | 5 +++++
>>  1 file changed, 5 insertions(+)
>> diff --git a/drivers/leds/led-core.c b/drivers/leds/led-core.c
>> index f1f718dbe0f8..9a5bfcd7a704 100644
>> --- a/drivers/leds/led-core.c
>> +++ b/drivers/leds/led-core.c
>> @@ -269,6 +269,11 @@ EXPORT_SYMBOL_GPL(led_set_brightness);
>>  void led_set_brightness_nopm(struct led_classdev *led_cdev,
>>  			      enum led_brightness value)
>>  {
>> +
>> +	if (led_cdev->flags & LED_SUSPENDED &&
>> +	    !__led_set_brightness_blocking(led_cdev, value))
>> +		return;
>> +
> 
> This function is "nopm" for a reason - we do not make here any
> pm management related operations.
> 
> Instead of that, please just add
> 
> flush_work(&led_cdev->set_brightness_work);
> 
> at the end of led_classdev_suspend()
> 
> in drivers/leds/led-class.c.

Right, will send v2.

Kai-Heng

> 
> -- 
> Best regards,
> Jacek Anaszewski


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

end of thread, other threads:[~2020-07-02  5:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-01  9:35 [PATCH] leds: core: Use blocking op for system suspend Kai-Heng Feng
2020-07-01 21:28 ` Jacek Anaszewski
2020-07-02  5:20   ` Kai-Heng Feng

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).