linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] PM / wakeup: Fix wakeup class wrecakge in -next
@ 2019-08-19 17:54 Stephen Boyd
  2019-08-19 17:54 ` [PATCH v3 1/2] PM / wakeup: Register wakeup class kobj after device is added Stephen Boyd
  2019-08-19 17:54 ` [PATCH v3 2/2] PM / wakeup: Unexport pm_wakeup_sysfs_{add,remove}() Stephen Boyd
  0 siblings, 2 replies; 6+ messages in thread
From: Stephen Boyd @ 2019-08-19 17:54 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: linux-kernel, linux-pm, Qian Cai, Tri Vo

Now a patch series because I found another patch to apply to unexport
some symbols.

Changes from v2:
 * Fix logic for not adding the wakeup class from dpm_sysfs_add()
 * Compile tested on !CONFIG_PM_SLEEP

Cc: Qian Cai <cai@lca.pw>
Cc: Tri Vo <trong@android.com>

Stephen Boyd (2):
  PM / wakeup: Register wakeup class kobj after device is added
  PM / wakeup: Unexport pm_wakeup_sysfs_{add,remove}()

 drivers/base/power/power.h        |  9 +++++++++
 drivers/base/power/sysfs.c        |  6 ++++++
 drivers/base/power/wakeup.c       | 10 ++++++----
 drivers/base/power/wakeup_stats.c | 15 +++++++++++++--
 4 files changed, 34 insertions(+), 6 deletions(-)


base-commit: 0c3d3d648b3ed72b920a89bc4fd125e9b7aa5f23
-- 
Sent by a computer through tubes


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

* [PATCH v3 1/2] PM / wakeup: Register wakeup class kobj after device is added
  2019-08-19 17:54 [PATCH v3 0/2] PM / wakeup: Fix wakeup class wrecakge in -next Stephen Boyd
@ 2019-08-19 17:54 ` Stephen Boyd
  2019-08-19 18:30   ` Tri Vo
  2019-08-19 17:54 ` [PATCH v3 2/2] PM / wakeup: Unexport pm_wakeup_sysfs_{add,remove}() Stephen Boyd
  1 sibling, 1 reply; 6+ messages in thread
From: Stephen Boyd @ 2019-08-19 17:54 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: linux-kernel, linux-pm, Qian Cai, Tri Vo

The device_set_wakeup_enable() function can be called on a device that
hasn't been registered with device_add() yet. This allows the device to
be in a state where wakeup is enabled for it but the device isn't
published to userspace in sysfs yet.

After commit 986845e747af ("PM / wakeup: Show wakeup sources stats in
sysfs"), calling device_set_wakeup_enable() will fail for a device that
hasn't been registered with the driver core via device_add(). This is
because we try to create sysfs entries for the device and associate a
wakeup class kobject with it before the device has been registered.

Let's follow a similar approach that device_set_wakeup_capable() takes
here and register the wakeup class either from
device_set_wakeup_enable() when the device is already registered, or
from dpm_sysfs_add() when the device is being registered with the driver
core via device_add().

Fixes: 986845e747af ("PM / wakeup: Show wakeup sources stats in sysfs")
Reported-by: Qian Cai <cai@lca.pw>
Cc: Qian Cai <cai@lca.pw>
Cc: Tri Vo <trong@android.com>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---

Any different name for pm_wakeup_source_sysfs_add() is fine with me.

 drivers/base/power/power.h        |  9 +++++++++
 drivers/base/power/sysfs.c        |  6 ++++++
 drivers/base/power/wakeup.c       | 10 ++++++----
 drivers/base/power/wakeup_stats.c | 13 +++++++++++++
 4 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index 57b1d1d88c8e..39a06a0cfdaa 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -157,4 +157,13 @@ extern int wakeup_source_sysfs_add(struct device *parent,
 				   struct wakeup_source *ws);
 extern void wakeup_source_sysfs_remove(struct wakeup_source *ws);
 
+extern int pm_wakeup_source_sysfs_add(struct device *parent);
+
+#else /* !CONFIG_PM_SLEEP */
+
+static inline int pm_wakeup_source_sysfs_add(struct device *parent)
+{
+	return 0;
+}
+
 #endif /* CONFIG_PM_SLEEP */
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
index 1b9c281cbe41..d7d82db2e4bc 100644
--- a/drivers/base/power/sysfs.c
+++ b/drivers/base/power/sysfs.c
@@ -5,6 +5,7 @@
 #include <linux/export.h>
 #include <linux/pm_qos.h>
 #include <linux/pm_runtime.h>
+#include <linux/pm_wakeup.h>
 #include <linux/atomic.h>
 #include <linux/jiffies.h>
 #include "power.h"
@@ -667,8 +668,13 @@ int dpm_sysfs_add(struct device *dev)
 		if (rc)
 			goto err_wakeup;
 	}
+	rc = pm_wakeup_source_sysfs_add(dev);
+	if (rc)
+		goto err_latency;
 	return 0;
 
+ err_latency:
+	sysfs_unmerge_group(&dev->kobj, &pm_qos_latency_tolerance_attr_group);
  err_wakeup:
 	sysfs_unmerge_group(&dev->kobj, &pm_wakeup_attr_group);
  err_runtime:
diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index f7925820b5ca..5817b51d2b15 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -220,10 +220,12 @@ struct wakeup_source *wakeup_source_register(struct device *dev,
 
 	ws = wakeup_source_create(name);
 	if (ws) {
-		ret = wakeup_source_sysfs_add(dev, ws);
-		if (ret) {
-			wakeup_source_free(ws);
-			return NULL;
+		if (!dev || device_is_registered(dev)) {
+			ret = wakeup_source_sysfs_add(dev, ws);
+			if (ret) {
+				wakeup_source_free(ws);
+				return NULL;
+			}
 		}
 		wakeup_source_add(ws);
 	}
diff --git a/drivers/base/power/wakeup_stats.c b/drivers/base/power/wakeup_stats.c
index 220a20ff8918..bc5e3945f7a8 100644
--- a/drivers/base/power/wakeup_stats.c
+++ b/drivers/base/power/wakeup_stats.c
@@ -184,6 +184,19 @@ int wakeup_source_sysfs_add(struct device *parent, struct wakeup_source *ws)
 }
 EXPORT_SYMBOL_GPL(wakeup_source_sysfs_add);
 
+/**
+ * pm_wakeup_source_sysfs_add - Add wakeup_source attributes to sysfs
+ * for a device if they're missing.
+ * @parent: Device given wakeup source is associated with
+ */
+int pm_wakeup_source_sysfs_add(struct device *parent)
+{
+	if (!parent->power.wakeup || parent->power.wakeup->dev)
+		return 0;
+
+	return wakeup_source_sysfs_add(parent, parent->power.wakeup);
+}
+
 /**
  * wakeup_source_sysfs_remove - Remove wakeup_source attributes from sysfs.
  * @ws: Wakeup source to be removed from sysfs.
-- 
Sent by a computer through tubes


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

* [PATCH v3 2/2] PM / wakeup: Unexport pm_wakeup_sysfs_{add,remove}()
  2019-08-19 17:54 [PATCH v3 0/2] PM / wakeup: Fix wakeup class wrecakge in -next Stephen Boyd
  2019-08-19 17:54 ` [PATCH v3 1/2] PM / wakeup: Register wakeup class kobj after device is added Stephen Boyd
@ 2019-08-19 17:54 ` Stephen Boyd
  2019-08-19 18:21   ` Stephen Boyd
  1 sibling, 1 reply; 6+ messages in thread
From: Stephen Boyd @ 2019-08-19 17:54 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: linux-kernel, linux-pm

These functions are just used by the PM core, and that isn't modular so
these functions don't need to be exported. Drop the exports.

Fixes: 986845e747af ("PM / wakeup: Show wakeup sources stats in sysfs")
Cc: Tri Vo <trong@android.com
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
---
 drivers/base/power/wakeup_stats.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/base/power/wakeup_stats.c b/drivers/base/power/wakeup_stats.c
index bc5e3945f7a8..c7734914d914 100644
--- a/drivers/base/power/wakeup_stats.c
+++ b/drivers/base/power/wakeup_stats.c
@@ -182,7 +182,6 @@ int wakeup_source_sysfs_add(struct device *parent, struct wakeup_source *ws)
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(wakeup_source_sysfs_add);
 
 /**
  * pm_wakeup_source_sysfs_add - Add wakeup_source attributes to sysfs
@@ -205,7 +204,6 @@ void wakeup_source_sysfs_remove(struct wakeup_source *ws)
 {
 	device_unregister(ws->dev);
 }
-EXPORT_SYMBOL_GPL(wakeup_source_sysfs_remove);
 
 static int __init wakeup_sources_sysfs_init(void)
 {
-- 
Sent by a computer through tubes


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

* Re: [PATCH v3 2/2] PM / wakeup: Unexport pm_wakeup_sysfs_{add,remove}()
  2019-08-19 17:54 ` [PATCH v3 2/2] PM / wakeup: Unexport pm_wakeup_sysfs_{add,remove}() Stephen Boyd
@ 2019-08-19 18:21   ` Stephen Boyd
  2019-08-19 18:32     ` Tri Vo
  0 siblings, 1 reply; 6+ messages in thread
From: Stephen Boyd @ 2019-08-19 18:21 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: linux-kernel, linux-pm, Tri Vo

Sorry, subject should be

PM / wakeup: Unexport wakeup_source_sysfs_{add,remove}()

Quoting Stephen Boyd (2019-08-19 10:54:57)
> These functions are just used by the PM core, and that isn't modular so
> these functions don't need to be exported. Drop the exports.
> 
> Fixes: 986845e747af ("PM / wakeup: Show wakeup sources stats in sysfs")
> Cc: Tri Vo <trong@android.com

Messed up the address here too. Should be

Cc: Tri Vo <trong@android.com>

> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> ---
>  drivers/base/power/wakeup_stats.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/base/power/wakeup_stats.c b/drivers/base/power/wakeup_stats.c
> index bc5e3945f7a8..c7734914d914 100644
> --- a/drivers/base/power/wakeup_stats.c
> +++ b/drivers/base/power/wakeup_stats.c
> @@ -182,7 +182,6 @@ int wakeup_source_sysfs_add(struct device *parent, struct wakeup_source *ws)
>  
>         return 0;
>  }
> -EXPORT_SYMBOL_GPL(wakeup_source_sysfs_add);
>  
>  /**
>   * pm_wakeup_source_sysfs_add - Add wakeup_source attributes to sysfs
> @@ -205,7 +204,6 @@ void wakeup_source_sysfs_remove(struct wakeup_source *ws)
>  {
>         device_unregister(ws->dev);
>  }
> -EXPORT_SYMBOL_GPL(wakeup_source_sysfs_remove);
>  
>  static int __init wakeup_sources_sysfs_init(void)
>  {

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

* Re: [PATCH v3 1/2] PM / wakeup: Register wakeup class kobj after device is added
  2019-08-19 17:54 ` [PATCH v3 1/2] PM / wakeup: Register wakeup class kobj after device is added Stephen Boyd
@ 2019-08-19 18:30   ` Tri Vo
  0 siblings, 0 replies; 6+ messages in thread
From: Tri Vo @ 2019-08-19 18:30 UTC (permalink / raw)
  To: Stephen Boyd; +Cc: Rafael J. Wysocki, LKML, Linux PM, Qian Cai

On Mon, Aug 19, 2019 at 10:55 AM Stephen Boyd <swboyd@chromium.org> wrote:
>
> The device_set_wakeup_enable() function can be called on a device that
> hasn't been registered with device_add() yet. This allows the device to
> be in a state where wakeup is enabled for it but the device isn't
> published to userspace in sysfs yet.
>
> After commit 986845e747af ("PM / wakeup: Show wakeup sources stats in
> sysfs"), calling device_set_wakeup_enable() will fail for a device that
> hasn't been registered with the driver core via device_add(). This is
> because we try to create sysfs entries for the device and associate a
> wakeup class kobject with it before the device has been registered.
>
> Let's follow a similar approach that device_set_wakeup_capable() takes
> here and register the wakeup class either from
> device_set_wakeup_enable() when the device is already registered, or
> from dpm_sysfs_add() when the device is being registered with the driver
> core via device_add().
>
> Fixes: 986845e747af ("PM / wakeup: Show wakeup sources stats in sysfs")
> Reported-by: Qian Cai <cai@lca.pw>
> Cc: Qian Cai <cai@lca.pw>
> Cc: Tri Vo <trong@android.com>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>

Reviewed-by: Tri Vo <trong@android.com>

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

* Re: [PATCH v3 2/2] PM / wakeup: Unexport pm_wakeup_sysfs_{add,remove}()
  2019-08-19 18:21   ` Stephen Boyd
@ 2019-08-19 18:32     ` Tri Vo
  0 siblings, 0 replies; 6+ messages in thread
From: Tri Vo @ 2019-08-19 18:32 UTC (permalink / raw)
  To: Stephen Boyd; +Cc: Rafael J. Wysocki, LKML, Linux PM

On Mon, Aug 19, 2019 at 11:21 AM Stephen Boyd <swboyd@chromium.org> wrote:
>
> Sorry, subject should be
>
> PM / wakeup: Unexport wakeup_source_sysfs_{add,remove}()
>
> Quoting Stephen Boyd (2019-08-19 10:54:57)
> > These functions are just used by the PM core, and that isn't modular so
> > these functions don't need to be exported. Drop the exports.
> >
> > Fixes: 986845e747af ("PM / wakeup: Show wakeup sources stats in sysfs")
> > Cc: Tri Vo <trong@android.com
>
> Messed up the address here too. Should be
>
> Cc: Tri Vo <trong@android.com>
>
> > Signed-off-by: Stephen Boyd <swboyd@chromium.org>

Reviewed-by: Tri Vo <trong@android.com>

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

end of thread, other threads:[~2019-08-19 18:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-19 17:54 [PATCH v3 0/2] PM / wakeup: Fix wakeup class wrecakge in -next Stephen Boyd
2019-08-19 17:54 ` [PATCH v3 1/2] PM / wakeup: Register wakeup class kobj after device is added Stephen Boyd
2019-08-19 18:30   ` Tri Vo
2019-08-19 17:54 ` [PATCH v3 2/2] PM / wakeup: Unexport pm_wakeup_sysfs_{add,remove}() Stephen Boyd
2019-08-19 18:21   ` Stephen Boyd
2019-08-19 18:32     ` Tri Vo

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