PM / wakeup: Do not fail dev_pm_attach_wake_irq() unnecessarily
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 5 Jan 2018 01:18:42 +0000 (02:18 +0100)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 9 Jan 2018 12:09:16 +0000 (13:09 +0100)
Returning an error code from dev_pm_attach_wake_irq() if
device_wakeup_attach_irq() called by it returns an error is
pointless, because the wakeup source used by it may be deleted
by user space via sysfs at any time and in particular right after
dev_pm_attach_wake_irq() has returned.  Moreover, it requires
the callers of dev_pm_attach_wake_irq() to create that wakeup
source via device_wakeup_enable() upfront, but that obviously is
racy with respect to the sysfs-based manipulations of it.

To avoid the race, modify device_wakeup_attach_irq() to check
that the wakeup source it is going to use is there (and return
early otherwise), make it void (as it cannot fail after that
change) and make dev_pm_attach_wake_irq() simply call it for
the device unconditionally.

Tested-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/power.h
drivers/base/power/wakeirq.c
drivers/base/power/wakeup.c

index 7beee75399d41f2811d10afbdf88b685b573fe27..21244c53e377deb5af8f041cd72e7a2b19f4d485 100644 (file)
@@ -41,20 +41,15 @@ extern void dev_pm_disable_wake_irq_check(struct device *dev);
 
 #ifdef CONFIG_PM_SLEEP
 
-extern int device_wakeup_attach_irq(struct device *dev,
-                                   struct wake_irq *wakeirq);
+extern void device_wakeup_attach_irq(struct device *dev, struct wake_irq *wakeirq);
 extern void device_wakeup_detach_irq(struct device *dev);
 extern void device_wakeup_arm_wake_irqs(void);
 extern void device_wakeup_disarm_wake_irqs(void);
 
 #else
 
-static inline int
-device_wakeup_attach_irq(struct device *dev,
-                        struct wake_irq *wakeirq)
-{
-       return 0;
-}
+static inline void device_wakeup_attach_irq(struct device *dev,
+                                           struct wake_irq *wakeirq) {}
 
 static inline void device_wakeup_detach_irq(struct device *dev)
 {
index ae0429827f31052fff58362131e171f33ff27a17..a8ac86e4d79e73f758301bdc8f690dddb795b671 100644 (file)
@@ -33,7 +33,6 @@ static int dev_pm_attach_wake_irq(struct device *dev, int irq,
                                  struct wake_irq *wirq)
 {
        unsigned long flags;
-       int err;
 
        if (!dev || !wirq)
                return -EINVAL;
@@ -45,12 +44,11 @@ static int dev_pm_attach_wake_irq(struct device *dev, int irq,
                return -EEXIST;
        }
 
-       err = device_wakeup_attach_irq(dev, wirq);
-       if (!err)
-               dev->power.wakeirq = wirq;
+       dev->power.wakeirq = wirq;
+       device_wakeup_attach_irq(dev, wirq);
 
        spin_unlock_irqrestore(&dev->power.lock, flags);
-       return err;
+       return 0;
 }
 
 /**
index b7b8b2fe89c6d6934677158298d0723c25719db9..e73a081c6397802f7af40ee0faf67330b0d471c5 100644 (file)
@@ -291,22 +291,19 @@ EXPORT_SYMBOL_GPL(device_wakeup_enable);
  *
  * Call under the device's power.lock lock.
  */
-int device_wakeup_attach_irq(struct device *dev,
+void device_wakeup_attach_irq(struct device *dev,
                             struct wake_irq *wakeirq)
 {
        struct wakeup_source *ws;
 
        ws = dev->power.wakeup;
-       if (!ws) {
-               dev_err(dev, "forgot to call device_init_wakeup?\n");
-               return -EINVAL;
-       }
+       if (!ws)
+               return;
 
        if (ws->wakeirq)
-               return -EEXIST;
+               dev_err(dev, "Leftover wakeup IRQ found, overriding\n");
 
        ws->wakeirq = wakeirq;
-       return 0;
 }
 
 /**