linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] power: supply: Init device wakeup after device_add()
@ 2019-08-01 21:33 Stephen Boyd
  2019-08-02  9:49 ` Rafael J. Wysocki
  2019-09-02  8:00 ` Sebastian Reichel
  0 siblings, 2 replies; 3+ messages in thread
From: Stephen Boyd @ 2019-08-01 21:33 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: linux-kernel, linux-pm, kernel-team, Greg Kroah-Hartman, Tri Vo,
	Kalesh Singh, Ravi Chandra Sadineni, Rafael J. Wysocki,
	Viresh Kumar

We may want to use the device pointer in device_init_wakeup() with
functions that expect the device to already be added with device_add().
For example, if we were to link the device initializing wakeup to
something in sysfs such as a class for wakeups we'll run into an error.
It looks like this code was written with the assumption that the device
would be added before initializing wakeup due to the order of operations
in power_supply_unregister().

Let's change the order of operations so we don't run into problems here.

Fixes: 948dcf966228 ("power_supply: Prevent suspend until power supply events are processed")
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>                                                                                                                      
Cc: Tri Vo <trong@android.com>                                                                                                                                             
Cc: Kalesh Singh <kaleshsingh@google.com>      
Cc: Ravi Chandra Sadineni <ravisadineni@chromium.org>
Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
Cc: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---

See this thread[1] for more information on how this will be necessary.

[1] https://lkml.kernel.org/r/20190731215514.212215-1-trong@android.com


 drivers/power/supply/power_supply_core.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
index 82e84801264c..5c36c430ce8b 100644
--- a/drivers/power/supply/power_supply_core.c
+++ b/drivers/power/supply/power_supply_core.c
@@ -1051,14 +1051,14 @@ __power_supply_register(struct device *parent,
 	}
 
 	spin_lock_init(&psy->changed_lock);
-	rc = device_init_wakeup(dev, ws);
-	if (rc)
-		goto wakeup_init_failed;
-
 	rc = device_add(dev);
 	if (rc)
 		goto device_add_failed;
 
+	rc = device_init_wakeup(dev, ws);
+	if (rc)
+		goto wakeup_init_failed;
+
 	rc = psy_register_thermal(psy);
 	if (rc)
 		goto register_thermal_failed;
@@ -1101,8 +1101,8 @@ __power_supply_register(struct device *parent,
 	psy_unregister_thermal(psy);
 register_thermal_failed:
 	device_del(dev);
-device_add_failed:
 wakeup_init_failed:
+device_add_failed:
 check_supplies_failed:
 dev_set_name_failed:
 	put_device(dev);
-- 
Sent by a computer through tubes


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

* Re: [PATCH] power: supply: Init device wakeup after device_add()
  2019-08-01 21:33 [PATCH] power: supply: Init device wakeup after device_add() Stephen Boyd
@ 2019-08-02  9:49 ` Rafael J. Wysocki
  2019-09-02  8:00 ` Sebastian Reichel
  1 sibling, 0 replies; 3+ messages in thread
From: Rafael J. Wysocki @ 2019-08-02  9:49 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: Sebastian Reichel, linux-kernel, linux-pm, kernel-team,
	Greg Kroah-Hartman, Tri Vo, Kalesh Singh, Ravi Chandra Sadineni,
	Viresh Kumar

On Thursday, August 1, 2019 11:33:30 PM CEST Stephen Boyd wrote:
> We may want to use the device pointer in device_init_wakeup() with
> functions that expect the device to already be added with device_add().
> For example, if we were to link the device initializing wakeup to
> something in sysfs such as a class for wakeups we'll run into an error.
> It looks like this code was written with the assumption that the device
> would be added before initializing wakeup due to the order of operations
> in power_supply_unregister().
> 
> Let's change the order of operations so we don't run into problems here.
> 
> Fixes: 948dcf966228 ("power_supply: Prevent suspend until power supply events are processed")
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>                                                                                                                      
> Cc: Tri Vo <trong@android.com>                                                                                                                                             
> Cc: Kalesh Singh <kaleshsingh@google.com>      
> Cc: Ravi Chandra Sadineni <ravisadineni@chromium.org>
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---
> 
> See this thread[1] for more information on how this will be necessary.
> 
> [1] https://lkml.kernel.org/r/20190731215514.212215-1-trong@android.com
> 
> 
>  drivers/power/supply/power_supply_core.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index 82e84801264c..5c36c430ce8b 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -1051,14 +1051,14 @@ __power_supply_register(struct device *parent,
>  	}
>  
>  	spin_lock_init(&psy->changed_lock);
> -	rc = device_init_wakeup(dev, ws);
> -	if (rc)
> -		goto wakeup_init_failed;
> -
>  	rc = device_add(dev);
>  	if (rc)
>  		goto device_add_failed;
>  
> +	rc = device_init_wakeup(dev, ws);
> +	if (rc)
> +		goto wakeup_init_failed;
> +
>  	rc = psy_register_thermal(psy);
>  	if (rc)
>  		goto register_thermal_failed;
> @@ -1101,8 +1101,8 @@ __power_supply_register(struct device *parent,
>  	psy_unregister_thermal(psy);
>  register_thermal_failed:
>  	device_del(dev);
> -device_add_failed:
>  wakeup_init_failed:
> +device_add_failed:
>  check_supplies_failed:
>  dev_set_name_failed:
>  	put_device(dev);
> 

Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>





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

* Re: [PATCH] power: supply: Init device wakeup after device_add()
  2019-08-01 21:33 [PATCH] power: supply: Init device wakeup after device_add() Stephen Boyd
  2019-08-02  9:49 ` Rafael J. Wysocki
@ 2019-09-02  8:00 ` Sebastian Reichel
  1 sibling, 0 replies; 3+ messages in thread
From: Sebastian Reichel @ 2019-09-02  8:00 UTC (permalink / raw)
  To: Stephen Boyd
  Cc: linux-kernel, linux-pm, kernel-team, Greg Kroah-Hartman, Tri Vo,
	Kalesh Singh, Ravi Chandra Sadineni, Rafael J. Wysocki,
	Viresh Kumar

[-- Attachment #1: Type: text/plain, Size: 2707 bytes --]

Hi,

On Thu, Aug 01, 2019 at 02:33:30PM -0700, Stephen Boyd wrote:
> We may want to use the device pointer in device_init_wakeup() with
> functions that expect the device to already be added with device_add().
> For example, if we were to link the device initializing wakeup to
> something in sysfs such as a class for wakeups we'll run into an error.
> It looks like this code was written with the assumption that the device
> would be added before initializing wakeup due to the order of operations
> in power_supply_unregister().
> 
> Let's change the order of operations so we don't run into problems here.
> 
> Fixes: 948dcf966228 ("power_supply: Prevent suspend until power supply events are processed")
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>                                                                                                                      
> Cc: Tri Vo <trong@android.com>                                                                                                                                             
> Cc: Kalesh Singh <kaleshsingh@google.com>      
> Cc: Ravi Chandra Sadineni <ravisadineni@chromium.org>
> Cc: "Rafael J. Wysocki" <rjw@rjwysocki.net>
> Cc: Viresh Kumar <viresh.kumar@linaro.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---

Thanks, queued.

-- Sebastian

> 
> See this thread[1] for more information on how this will be necessary.
> 
> [1] https://lkml.kernel.org/r/20190731215514.212215-1-trong@android.com
> 
> 
>  drivers/power/supply/power_supply_core.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c
> index 82e84801264c..5c36c430ce8b 100644
> --- a/drivers/power/supply/power_supply_core.c
> +++ b/drivers/power/supply/power_supply_core.c
> @@ -1051,14 +1051,14 @@ __power_supply_register(struct device *parent,
>  	}
>  
>  	spin_lock_init(&psy->changed_lock);
> -	rc = device_init_wakeup(dev, ws);
> -	if (rc)
> -		goto wakeup_init_failed;
> -
>  	rc = device_add(dev);
>  	if (rc)
>  		goto device_add_failed;
>  
> +	rc = device_init_wakeup(dev, ws);
> +	if (rc)
> +		goto wakeup_init_failed;
> +
>  	rc = psy_register_thermal(psy);
>  	if (rc)
>  		goto register_thermal_failed;
> @@ -1101,8 +1101,8 @@ __power_supply_register(struct device *parent,
>  	psy_unregister_thermal(psy);
>  register_thermal_failed:
>  	device_del(dev);
> -device_add_failed:
>  wakeup_init_failed:
> +device_add_failed:
>  check_supplies_failed:
>  dev_set_name_failed:
>  	put_device(dev);
> -- 
> Sent by a computer through tubes
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

end of thread, other threads:[~2019-09-02  8:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-01 21:33 [PATCH] power: supply: Init device wakeup after device_add() Stephen Boyd
2019-08-02  9:49 ` Rafael J. Wysocki
2019-09-02  8:00 ` Sebastian Reichel

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