linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] leds/trigger: system can't enter suspend.
@ 2017-05-07  2:01 sanshan zhang
  2017-05-07  8:30 ` Pavel Machek
  2017-05-10 20:51 ` Jacek Anaszewski
  0 siblings, 2 replies; 4+ messages in thread
From: sanshan zhang @ 2017-05-07  2:01 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-leds, pavel, j.anaszewski, rpurdie

From: zhang sanshan <sanshan.zhang@nxp.com>

system can't enter suspend when enable led heartbeat.

pm will call heartbeat_pm_notifier when suspend.
system will prepare led states, and led_trigger_unregister
will use led_trigger_set to set trigger.
kobject_uevent_env will send event,it will call ep_poll_callback
to hold a wakeup source if we enable wakelock in kernel.
So that system can't enter suspend.

If we set led device tigger to NONE, there is not need to
send notification to user space.

Change-Id: I9f7ee5764d7e31b9a225dae5517cb36137675f9d
Signed-off-by: zhang sanshan <sanshan.zhang@nxp.com>
Signed-off-by: Zhang Bo <bo.zhang@nxp.com>
---
 drivers/leds/led-triggers.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
index 431123b..f03c2bd1 100644
--- a/drivers/leds/led-triggers.c
+++ b/drivers/leds/led-triggers.c
@@ -108,13 +108,10 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
 	unsigned long flags;
 	char *event = NULL;
 	char *envp[2];
-	const char *name;
 
 	if (!led_cdev->trigger && !trig)
 		return;
 
-	name = trig ? trig->name : "none";
-	event = kasprintf(GFP_KERNEL, "TRIGGER=%s", name);
 
 	/* Remove any existing trigger */
 	if (led_cdev->trigger) {
@@ -138,6 +135,10 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
 			trig->activate(led_cdev);
 	}
 
+	if (NULL != trig)
+		event = kasprintf(GFP_KERNEL, "TRIGGER=%s", trig->name);
+	else
+		return;
 	if (event) {
 		envp[0] = event;
 		envp[1] = NULL;
-- 
1.9.1

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

* Re: [PATCH] leds/trigger: system can't enter suspend.
  2017-05-07  2:01 [PATCH] leds/trigger: system can't enter suspend sanshan zhang
@ 2017-05-07  8:30 ` Pavel Machek
  2017-05-07 10:55   ` Pete Zhang
  2017-05-10 20:51 ` Jacek Anaszewski
  1 sibling, 1 reply; 4+ messages in thread
From: Pavel Machek @ 2017-05-07  8:30 UTC (permalink / raw)
  To: sanshan zhang; +Cc: linux-kernel, linux-leds, j.anaszewski, rpurdie

On Sun 2017-05-07 10:01:21, sanshan zhang wrote:
> From: zhang sanshan <sanshan.zhang@nxp.com>
> 
> system can't enter suspend when enable led heartbeat.
> 
> pm will call heartbeat_pm_notifier when suspend.
> system will prepare led states, and led_trigger_unregister
> will use led_trigger_set to set trigger.
> kobject_uevent_env will send event,it will call ep_poll_callback
> to hold a wakeup source if we enable wakelock in kernel.
> So that system can't enter suspend.
> 
> If we set led device tigger to NONE, there is not need to
> send notification to user space.

Does this bug also happen on mainline kernels?

Are you sure noone relies on the "none" trigger behaviour? We usually
don't change user interface without good reason.

Actually.. is someone using those notifications at all? Telling userland
that userland changed LED trigger is somehow... interesting.

									Pavel

> 
> Change-Id: I9f7ee5764d7e31b9a225dae5517cb36137675f9d
> Signed-off-by: zhang sanshan <sanshan.zhang@nxp.com>
> Signed-off-by: Zhang Bo <bo.zhang@nxp.com>
> ---
>  drivers/leds/led-triggers.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
> index 431123b..f03c2bd1 100644
> --- a/drivers/leds/led-triggers.c
> +++ b/drivers/leds/led-triggers.c
> @@ -108,13 +108,10 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
>  	unsigned long flags;
>  	char *event = NULL;
>  	char *envp[2];
> -	const char *name;
>  
>  	if (!led_cdev->trigger && !trig)
>  		return;
>  
> -	name = trig ? trig->name : "none";
> -	event = kasprintf(GFP_KERNEL, "TRIGGER=%s", name);
>  
>  	/* Remove any existing trigger */
>  	if (led_cdev->trigger) {
> @@ -138,6 +135,10 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
>  			trig->activate(led_cdev);
>  	}
>  
> +	if (NULL != trig)
> +		event = kasprintf(GFP_KERNEL, "TRIGGER=%s", trig->name);
> +	else
> +		return;
>  	if (event) {
>  		envp[0] = event;
>  		envp[1] = NULL;
> -- 
> 1.9.1

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* RE: [PATCH] leds/trigger: system can't enter suspend.
  2017-05-07  8:30 ` Pavel Machek
@ 2017-05-07 10:55   ` Pete Zhang
  0 siblings, 0 replies; 4+ messages in thread
From: Pete Zhang @ 2017-05-07 10:55 UTC (permalink / raw)
  To: Pavel Machek; +Cc: linux-kernel, linux-leds, j.anaszewski, rpurdie

Please see my comments inline.

-----Original Message-----
From: Pavel Machek [mailto:pavel@ucw.cz] 
Sent: Sunday, May 07, 2017 4:30 PM
To: Pete Zhang
Cc: linux-kernel@vger.kernel.org; linux-leds@vger.kernel.org; j.anaszewski@samsung.com; rpurdie@rpsys.net
Subject: Re: [PATCH] leds/trigger: system can't enter suspend.

On Sun 2017-05-07 10:01:21, sanshan zhang wrote:
> From: zhang sanshan <sanshan.zhang@nxp.com>
> 
> system can't enter suspend when enable led heartbeat.
> 
> pm will call heartbeat_pm_notifier when suspend.
> system will prepare led states, and led_trigger_unregister will use 
> led_trigger_set to set trigger.
> kobject_uevent_env will send event,it will call ep_poll_callback to 
> hold a wakeup source if we enable wakelock in kernel.
> So that system can't enter suspend.
> 
> If we set led device tigger to NONE, there is not need to send 
> notification to user space.

Does this bug also happen on mainline kernels?

[Sanshan]: We found this bug in kernel 4.9, But I think it also can reproduce in mainline
 
Are you sure noone relies on the "none" trigger behaviour? We usually don't change user interface without good reason.

[Sanshan]:  From android's perspective, we do not use 'none' trigger. If we set the trigger to 'none', the sys node have been deregistered, 
            There is no mean to notify userland to change the permission of sys node. 

Actually.. is someone using those notifications at all? Telling userland that userland changed LED trigger is somehow... interesting.
[sanshan] : Yes, maybe the effect of this patch is userland can't know current trigger is 'none'

[Sanshan]: I don't know whether we can just turn off the LED rather than registering the led trigger when suspend. 

 

								

> 
> Change-Id: I9f7ee5764d7e31b9a225dae5517cb36137675f9d
> Signed-off-by: zhang sanshan <sanshan.zhang@nxp.com>
> Signed-off-by: Zhang Bo <bo.zhang@nxp.com>
> ---
>  drivers/leds/led-triggers.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c 
> index 431123b..f03c2bd1 100644
> --- a/drivers/leds/led-triggers.c
> +++ b/drivers/leds/led-triggers.c
> @@ -108,13 +108,10 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
>  	unsigned long flags;
>  	char *event = NULL;
>  	char *envp[2];
> -	const char *name;
>  
>  	if (!led_cdev->trigger && !trig)
>  		return;
>  
> -	name = trig ? trig->name : "none";
> -	event = kasprintf(GFP_KERNEL, "TRIGGER=%s", name);
>  
>  	/* Remove any existing trigger */
>  	if (led_cdev->trigger) {
> @@ -138,6 +135,10 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
>  			trig->activate(led_cdev);
>  	}
>  
> +	if (NULL != trig)
> +		event = kasprintf(GFP_KERNEL, "TRIGGER=%s", trig->name);
> +	else
> +		return;
>  	if (event) {
>  		envp[0] = event;
>  		envp[1] = NULL;
> --
> 1.9.1

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [PATCH] leds/trigger: system can't enter suspend.
  2017-05-07  2:01 [PATCH] leds/trigger: system can't enter suspend sanshan zhang
  2017-05-07  8:30 ` Pavel Machek
@ 2017-05-10 20:51 ` Jacek Anaszewski
  1 sibling, 0 replies; 4+ messages in thread
From: Jacek Anaszewski @ 2017-05-10 20:51 UTC (permalink / raw)
  To: sanshan zhang, linux-kernel; +Cc: linux-leds, pavel, j.anaszewski, rpurdie

Hi Zhang,

Thanks for the patch.

I'd rather keep sending uevent on setting trigger to "none".

We could get rid of the problem you're trying to fix,
by modifying heartbeat_pm_notifier() so that it didn't go
through the whole procedure of unregistering/registering
the trigger on suspend/resume.

Instead of that we would need to add suspend/resume
ops to the struct led_trigger, that could be implemented
by triggers similarly to activate/deactivate.

We'd need also the led_trigger_suspend{resume}() API
that would iterate through all LED class devices registered
on given trigger and call their suspend/resume ops.

In this specifc case of ledtrig-heartbeat, that suspend
op would need only to call

del_timer_sync(&led_cdev->trigger_data->timer);

and resume would need to call setup_timer() accordingly.

led_trigger_suspend{resume} would replace
led_trigger_unregister{register} in heartbeat_pm_notifier().

I hope this rough design makes sense :-)

Best regards,
Jacek Anaszewski


On 05/07/2017 04:01 AM, sanshan zhang wrote:
> From: zhang sanshan <sanshan.zhang@nxp.com>
> 
> system can't enter suspend when enable led heartbeat.
> 
> pm will call heartbeat_pm_notifier when suspend.
> system will prepare led states, and led_trigger_unregister
> will use led_trigger_set to set trigger.
> kobject_uevent_env will send event,it will call ep_poll_callback
> to hold a wakeup source if we enable wakelock in kernel.
> So that system can't enter suspend.
> 
> If we set led device tigger to NONE, there is not need to
> send notification to user space.
> 
> Change-Id: I9f7ee5764d7e31b9a225dae5517cb36137675f9d
> Signed-off-by: zhang sanshan <sanshan.zhang@nxp.com>
> Signed-off-by: Zhang Bo <bo.zhang@nxp.com>
> ---
>  drivers/leds/led-triggers.c | 7 ++++---
>  1 file changed, 4 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c
> index 431123b..f03c2bd1 100644
> --- a/drivers/leds/led-triggers.c
> +++ b/drivers/leds/led-triggers.c
> @@ -108,13 +108,10 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
>  	unsigned long flags;
>  	char *event = NULL;
>  	char *envp[2];
> -	const char *name;
>  
>  	if (!led_cdev->trigger && !trig)
>  		return;
>  
> -	name = trig ? trig->name : "none";
> -	event = kasprintf(GFP_KERNEL, "TRIGGER=%s", name);
>  
>  	/* Remove any existing trigger */
>  	if (led_cdev->trigger) {
> @@ -138,6 +135,10 @@ void led_trigger_set(struct led_classdev *led_cdev, struct led_trigger *trig)
>  			trig->activate(led_cdev);
>  	}
>  
> +	if (NULL != trig)
> +		event = kasprintf(GFP_KERNEL, "TRIGGER=%s", trig->name);
> +	else
> +		return;
>  	if (event) {
>  		envp[0] = event;
>  		envp[1] = NULL;
> 

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

end of thread, other threads:[~2017-05-10 20:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-07  2:01 [PATCH] leds/trigger: system can't enter suspend sanshan zhang
2017-05-07  8:30 ` Pavel Machek
2017-05-07 10:55   ` Pete Zhang
2017-05-10 20:51 ` Jacek Anaszewski

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