Commit 49550709 authored by John Stultz's avatar John Stultz Committed by Rafael J. Wysocki

PM / wakeup: Use irqsave/irqrestore for events_lock

Jon Medhurst (Tixy) recently noticed a problem with the
events_lock usage. One of the Android patches that uses
wakeup_sources calls wakeup_source_add() with irqs disabled.
However, the event_lock usage in wakeup_source_add() uses
spin_lock_irq()/spin_unlock_irq(), which reenables interrupts.
This results in lockdep warnings.

The fix is to use spin_lock_irqsave()/spin_lock_irqrestore()
instead for the events_lock.

References: https://bugs.launchpad.net/linaro-landing-team-arm/+bug/1037565Reported-and-debugged-by: default avatarJon Medhurst (Tixy) <tixy@linaro.org>
Signed-off-by: default avatarJohn Stultz <john.stultz@linaro.org>
Signed-off-by: default avatarRafael J. Wysocki <rjw@sisk.pl>
parent 5834ec3a
...@@ -127,6 +127,8 @@ EXPORT_SYMBOL_GPL(wakeup_source_destroy); ...@@ -127,6 +127,8 @@ EXPORT_SYMBOL_GPL(wakeup_source_destroy);
*/ */
void wakeup_source_add(struct wakeup_source *ws) void wakeup_source_add(struct wakeup_source *ws)
{ {
unsigned long flags;
if (WARN_ON(!ws)) if (WARN_ON(!ws))
return; return;
...@@ -135,9 +137,9 @@ void wakeup_source_add(struct wakeup_source *ws) ...@@ -135,9 +137,9 @@ void wakeup_source_add(struct wakeup_source *ws)
ws->active = false; ws->active = false;
ws->last_time = ktime_get(); ws->last_time = ktime_get();
spin_lock_irq(&events_lock); spin_lock_irqsave(&events_lock, flags);
list_add_rcu(&ws->entry, &wakeup_sources); list_add_rcu(&ws->entry, &wakeup_sources);
spin_unlock_irq(&events_lock); spin_unlock_irqrestore(&events_lock, flags);
} }
EXPORT_SYMBOL_GPL(wakeup_source_add); EXPORT_SYMBOL_GPL(wakeup_source_add);
...@@ -147,12 +149,14 @@ EXPORT_SYMBOL_GPL(wakeup_source_add); ...@@ -147,12 +149,14 @@ EXPORT_SYMBOL_GPL(wakeup_source_add);
*/ */
void wakeup_source_remove(struct wakeup_source *ws) void wakeup_source_remove(struct wakeup_source *ws)
{ {
unsigned long flags;
if (WARN_ON(!ws)) if (WARN_ON(!ws))
return; return;
spin_lock_irq(&events_lock); spin_lock_irqsave(&events_lock, flags);
list_del_rcu(&ws->entry); list_del_rcu(&ws->entry);
spin_unlock_irq(&events_lock); spin_unlock_irqrestore(&events_lock, flags);
synchronize_rcu(); synchronize_rcu();
} }
EXPORT_SYMBOL_GPL(wakeup_source_remove); EXPORT_SYMBOL_GPL(wakeup_source_remove);
...@@ -752,15 +756,16 @@ bool pm_get_wakeup_count(unsigned int *count, bool block) ...@@ -752,15 +756,16 @@ bool pm_get_wakeup_count(unsigned int *count, bool block)
bool pm_save_wakeup_count(unsigned int count) bool pm_save_wakeup_count(unsigned int count)
{ {
unsigned int cnt, inpr; unsigned int cnt, inpr;
unsigned long flags;
events_check_enabled = false; events_check_enabled = false;
spin_lock_irq(&events_lock); spin_lock_irqsave(&events_lock, flags);
split_counters(&cnt, &inpr); split_counters(&cnt, &inpr);
if (cnt == count && inpr == 0) { if (cnt == count && inpr == 0) {
saved_count = count; saved_count = count;
events_check_enabled = true; events_check_enabled = true;
} }
spin_unlock_irq(&events_lock); spin_unlock_irqrestore(&events_lock, flags);
return events_check_enabled; return events_check_enabled;
} }
......
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