From: Ulf Hansson <ulf.hansson@linaro.org>
To: "Rafael J . Wysocki" <rjw@rjwysocki.net>, linux-pm@vger.kernel.org
Cc: Kevin Hilman <khilman@kernel.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Simon Horman <horms@verge.net.au>,
Niklas Soderlund <niklas.soderlund+renesas@ragnatech.se>,
Vincent Guittot <vincent.guittot@linaro.org>,
linux-renesas-soc@vger.kernel.org,
Ulf Hansson <ulf.hansson@linaro.org>
Subject: [PATCH v2 4/4] PM / core: Print warn if device gets enabled as wakeup source during sleep
Date: Fri, 29 Dec 2017 12:37:03 +0100 [thread overview]
Message-ID: <1514547423-18965-5-git-send-email-ulf.hansson@linaro.org> (raw)
In-Reply-To: <1514547423-18965-1-git-send-email-ulf.hansson@linaro.org>
In general, wakeup settings are not supposed to be changed during any of
the system wide PM phases. The reason is simply that it would break
guarantees provided by the PM core, to properly act on active wakeup
sources.
However, there are exceptions to when, in particular, disabling a device as
wakeup source makes sense. For example, in cases when a driver realizes
that its device is dead during system suspend. For these scenarios, we
don't need to care about acting on the wakeup source correctly, because a
dead device shouldn't deliver wakeup signals.
To this reasoning and to help users to properly manage wakeup settings,
let's print a warning in cases someone calls device_wakeup_enable() during
system sleep.
Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
---
drivers/base/power/main.c | 4 ++++
drivers/base/power/wakeup.c | 4 ++++
include/linux/pm.h | 1 +
3 files changed, 9 insertions(+)
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 1327726..6b0d312 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -1030,6 +1030,8 @@ static void device_complete(struct device *dev, pm_message_t state)
callback(dev);
}
+ dev->power.may_set_wakeup = dev->power.can_wakeup;
+
device_unlock(dev);
pm_runtime_put(dev);
@@ -1747,6 +1749,7 @@ static int device_prepare(struct device *dev, pm_message_t state)
device_lock(dev);
+ dev->power.may_set_wakeup = false;
dev->power.wakeup_path = false;
if (dev->power.no_pm_callbacks) {
@@ -1775,6 +1778,7 @@ static int device_prepare(struct device *dev, pm_message_t state)
if (ret < 0) {
suspend_report_result(callback, ret);
pm_runtime_put(dev);
+ dev->power.may_set_wakeup = dev->power.can_wakeup;
return ret;
}
/*
diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index cb72965..5445bea 100644
--- a/drivers/base/power/wakeup.c
+++ b/drivers/base/power/wakeup.c
@@ -268,6 +268,9 @@ int device_wakeup_enable(struct device *dev)
if (!dev || !dev->power.can_wakeup)
return -EINVAL;
+ if (!dev->power.may_set_wakeup)
+ dev_warn(dev, "don't enable as wakup source during sleep!\n");
+
ws = wakeup_source_register(dev_name(dev));
if (!ws)
return -ENOMEM;
@@ -413,6 +416,7 @@ void device_set_wakeup_capable(struct device *dev, bool capable)
return;
dev->power.can_wakeup = capable;
+ dev->power.may_set_wakeup = capable;
if (device_is_registered(dev) && !list_empty(&dev->power.entry)) {
if (capable) {
int ret = wakeup_sysfs_add(dev);
diff --git a/include/linux/pm.h b/include/linux/pm.h
index ebc6ef8..106fb15 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -606,6 +606,7 @@ struct dev_pm_info {
struct list_head entry;
struct completion completion;
struct wakeup_source *wakeup;
+ bool may_set_wakeup:1;
bool wakeup_path:1;
bool syscore:1;
bool no_pm_callbacks:1; /* Owned by the PM core */
--
2.7.4
next prev parent reply other threads:[~2017-12-29 11:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-29 11:36 [PATCH v2 0/4] PM / core: Extend behaviour for wakeup paths Ulf Hansson
2017-12-29 11:37 ` [PATCH v2 1/4] PM / core: Assign the wakeup_path status flag in __device_prepare() Ulf Hansson
2017-12-30 0:44 ` Rafael J. Wysocki
2018-01-02 11:36 ` Ulf Hansson
2018-01-02 11:43 ` Rafael J. Wysocki
2018-01-02 13:17 ` Ulf Hansson
2017-12-29 11:37 ` [PATCH v2 2/4] PM / core: Add WAKEUP_PATH driver flag Ulf Hansson
2017-12-29 11:37 ` [PATCH v2 3/4] PM / Domains: Take WAKEUP_PATH driver flag into account in genpd Ulf Hansson
2017-12-30 0:47 ` Rafael J. Wysocki
2018-01-02 11:46 ` Ulf Hansson
2018-01-02 11:52 ` Rafael J. Wysocki
2017-12-29 11:37 ` Ulf Hansson [this message]
2017-12-30 0:58 ` [PATCH v2 4/4] PM / core: Print warn if device gets enabled as wakeup source during sleep Rafael J. Wysocki
2018-01-02 12:30 ` Ulf Hansson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1514547423-18965-5-git-send-email-ulf.hansson@linaro.org \
--to=ulf.hansson@linaro.org \
--cc=geert+renesas@glider.be \
--cc=horms@verge.net.au \
--cc=khilman@kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=niklas.soderlund+renesas@ragnatech.se \
--cc=rjw@rjwysocki.net \
--cc=vincent.guittot@linaro.org \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.