PM / wakeup: Rework wakeup source timer cancellation
authorViresh Kumar <viresh.kumar@linaro.org>
Fri, 8 Mar 2019 09:53:11 +0000 (15:23 +0530)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 12 Mar 2019 08:40:48 +0000 (09:40 +0100)
If wakeup_source_add() is called right after wakeup_source_remove()
for the same wakeup source, timer_setup() may be called for a
potentially scheduled timer which is incorrect.

To avoid that, move the wakeup source timer cancellation from
wakeup_source_drop() to wakeup_source_remove().

Moreover, make wakeup_source_remove() clear the timer function after
canceling the timer to let wakeup_source_not_registered() treat
unregistered wakeup sources in the same way as the ones that have
never been registered.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
Cc: 4.4+ <stable@vger.kernel.org> # 4.4+
[ rjw: Subject, changelog, merged two patches together ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/wakeup.c

index f1fee72ed970a50e7501c7be11ebe34da38c580a..a25d2d82f44deae11679031c56830cdc9645605e 100644 (file)
@@ -118,7 +118,6 @@ void wakeup_source_drop(struct wakeup_source *ws)
        if (!ws)
                return;
 
-       del_timer_sync(&ws->timer);
        __pm_relax(ws);
 }
 EXPORT_SYMBOL_GPL(wakeup_source_drop);
@@ -205,6 +204,13 @@ void wakeup_source_remove(struct wakeup_source *ws)
        list_del_rcu(&ws->entry);
        raw_spin_unlock_irqrestore(&events_lock, flags);
        synchronize_srcu(&wakeup_srcu);
+
+       del_timer_sync(&ws->timer);
+       /*
+        * Clear timer.function to make wakeup_source_not_registered() treat
+        * this wakeup source as not registered.
+        */
+       ws->timer.function = NULL;
 }
 EXPORT_SYMBOL_GPL(wakeup_source_remove);