]> git.karo-electronics.de Git - mv-sheeva.git/commitdiff
PM / Sleep: Fix possible infinite loop during wakeup source destruction
authorRafael J. Wysocki <rjw@sisk.pl>
Fri, 17 Feb 2012 22:39:20 +0000 (23:39 +0100)
committerRafael J. Wysocki <rjw@sisk.pl>
Sun, 4 Mar 2012 22:08:02 +0000 (23:08 +0100)
If wakeup_source_destroy() is called for an active wakeup source that
is never deactivated, it will spin forever.  To prevent that from
happening, make wakeup_source_destroy() call __pm_relax() for the
wakeup source object it is about to free instead of waiting until
it will be deactivated by someone else.  However, for this to work
it also needs to make sure that the timer function will not be
executed after the final __pm_relax(), so make it run
del_timer_sync() on the wakeup source's timer beforehand.

Additionally, update the kerneldoc comment to document the
requirement that __pm_stay_awake() and __pm_wakeup_event() must not
be run in parallel with wakeup_source_destroy().

Reported-by: Arve Hjønnevåg <arve@android.com>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
drivers/base/power/wakeup.c

index 6e591a8a49da1aa873e1ae61197abde0008c9575..d279f462d62430d225a123489fd19824f669b4b4 100644 (file)
@@ -74,22 +74,17 @@ EXPORT_SYMBOL_GPL(wakeup_source_create);
 /**
  * wakeup_source_destroy - Destroy a struct wakeup_source object.
  * @ws: Wakeup source to destroy.
+ *
+ * Callers must ensure that __pm_stay_awake() or __pm_wakeup_event() will never
+ * be run in parallel with this function for the same wakeup source object.
  */
 void wakeup_source_destroy(struct wakeup_source *ws)
 {
        if (!ws)
                return;
 
-       spin_lock_irq(&ws->lock);
-       while (ws->active) {
-               spin_unlock_irq(&ws->lock);
-
-               schedule_timeout_interruptible(msecs_to_jiffies(TIMEOUT));
-
-               spin_lock_irq(&ws->lock);
-       }
-       spin_unlock_irq(&ws->lock);
-
+       del_timer_sync(&ws->timer);
+       __pm_relax(ws);
        kfree(ws->name);
        kfree(ws);
 }