1 From 1fad17fb1bbcd73159c2b992668a6957ecc5af8a Mon Sep 17 00:00:00 2001
2 From: Viresh Kumar <viresh.kumar@linaro.org>
3 Date: Fri, 8 Mar 2019 15:23:11 +0530
4 Subject: PM / wakeup: Rework wakeup source timer cancellation
6 From: Viresh Kumar <viresh.kumar@linaro.org>
8 commit 1fad17fb1bbcd73159c2b992668a6957ecc5af8a upstream.
10 If wakeup_source_add() is called right after wakeup_source_remove()
11 for the same wakeup source, timer_setup() may be called for a
12 potentially scheduled timer which is incorrect.
14 To avoid that, move the wakeup source timer cancellation from
15 wakeup_source_drop() to wakeup_source_remove().
17 Moreover, make wakeup_source_remove() clear the timer function after
18 canceling the timer to let wakeup_source_not_registered() treat
19 unregistered wakeup sources in the same way as the ones that have
20 never been registered.
22 Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
23 Cc: 4.4+ <stable@vger.kernel.org> # 4.4+
24 [ rjw: Subject, changelog, merged two patches together ]
25 Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
26 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
29 drivers/base/power/wakeup.c | 8 +++++++-
30 1 file changed, 7 insertions(+), 1 deletion(-)
32 --- a/drivers/base/power/wakeup.c
33 +++ b/drivers/base/power/wakeup.c
34 @@ -118,7 +118,6 @@ void wakeup_source_drop(struct wakeup_so
38 - del_timer_sync(&ws->timer);
41 EXPORT_SYMBOL_GPL(wakeup_source_drop);
42 @@ -205,6 +204,13 @@ void wakeup_source_remove(struct wakeup_
43 list_del_rcu(&ws->entry);
44 raw_spin_unlock_irqrestore(&events_lock, flags);
45 synchronize_srcu(&wakeup_srcu);
47 + del_timer_sync(&ws->timer);
49 + * Clear timer.function to make wakeup_source_not_registered() treat
50 + * this wakeup source as not registered.
52 + ws->timer.function = NULL;
54 EXPORT_SYMBOL_GPL(wakeup_source_remove);