summaryrefslogtreecommitdiff
path: root/drivers/base/power/wakeup.c
diff options
context:
space:
mode:
authorStephen Boyd <swboyd@chromium.org>2019-08-19 15:41:57 -0700
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2019-08-21 00:25:16 +0200
commit2ca3d1ecb8c432ee212d80fa7615cdd5d1df62e3 (patch)
tree89b3ae2a339df6e794c3f7efef474a3e089e8185 /drivers/base/power/wakeup.c
parentae367b7936408444afc76a8a3e141abede9ccbe4 (diff)
PM / wakeup: Register wakeup class kobj after device is added
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 c8377adfa781 ("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: c8377adfa781 ("PM / wakeup: Show wakeup sources stats in sysfs") Reported-by: Qian Cai <cai@lca.pw> Reviewed-by: Tri Vo <trong@android.com> Signed-off-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/base/power/wakeup.c')
-rw-r--r--drivers/base/power/wakeup.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
index 036469528f88..e58b070985b1 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);
}