Commit 4782e165 authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

PM / Sleep: Make __pm_stay_awake() delete wakeup source timers

If __pm_stay_awake() is called after __pm_wakeup_event() for the same
wakep source object before its timer expires, it won't cancel the
timer, so the wakeup source will be deactivated from the timer
function as scheduled by __pm_wakeup_event().  In that case
__pm_stay_awake() doesn't have any effect beyond incrementing
the wakeup source's event_count field, although it should cancel
the timer and make the wakeup source stay active until __pm_relax()
is called for it.

To fix this problem make __pm_stay_awake() delete the wakeup source's
timer and ensure that it won't be deactivated from the timer funtion
afterwards by clearing its timer_expires field.
Reported-by: default avatarArve Hjønnevåg <arve@android.com>
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
parent da863cdd
...@@ -344,7 +344,6 @@ static void wakeup_source_activate(struct wakeup_source *ws) ...@@ -344,7 +344,6 @@ static void wakeup_source_activate(struct wakeup_source *ws)
{ {
ws->active = true; ws->active = true;
ws->active_count++; ws->active_count++;
ws->timer_expires = jiffies;
ws->last_time = ktime_get(); ws->last_time = ktime_get();
/* Increment the counter of events in progress. */ /* Increment the counter of events in progress. */
...@@ -365,9 +364,14 @@ void __pm_stay_awake(struct wakeup_source *ws) ...@@ -365,9 +364,14 @@ void __pm_stay_awake(struct wakeup_source *ws)
return; return;
spin_lock_irqsave(&ws->lock, flags); spin_lock_irqsave(&ws->lock, flags);
ws->event_count++; ws->event_count++;
if (!ws->active) if (!ws->active)
wakeup_source_activate(ws); wakeup_source_activate(ws);
del_timer(&ws->timer);
ws->timer_expires = 0;
spin_unlock_irqrestore(&ws->lock, flags); spin_unlock_irqrestore(&ws->lock, flags);
} }
EXPORT_SYMBOL_GPL(__pm_stay_awake); EXPORT_SYMBOL_GPL(__pm_stay_awake);
...@@ -541,7 +545,7 @@ void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec) ...@@ -541,7 +545,7 @@ void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec)
if (!expires) if (!expires)
expires = 1; expires = 1;
if (time_after(expires, ws->timer_expires)) { if (!ws->timer_expires || time_after(expires, ws->timer_expires)) {
mod_timer(&ws->timer, expires); mod_timer(&ws->timer, expires);
ws->timer_expires = expires; ws->timer_expires = expires;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment