]> xenbits.xensource.com Git - people/aperard/linux-chromebook.git/commitdiff
UPSTREAM: RTC: Avoid races between RTC alarm wakeup and suspend.
authorNeilBrown <neilb@suse.de>
Sun, 5 Aug 2012 20:56:20 +0000 (22:56 +0200)
committerGerrit <chrome-bot@google.com>
Tue, 27 Nov 2012 21:14:37 +0000 (13:14 -0800)
If an RTC alarm fires just as suspend is happening, it is possible for
suspend to complete and the alarm to be missed.

To avoid the race, we must register the event with the PM core.

As the event is made visible to userspace through a thread which is
only scheduled by the interrupt, we need a pm_stay_awake/pm_relax
pair preventing suspend from the interrupt until the thread completes
its work.

This makes the pm_wakeup_event() call in cmos_interrupt unnecessary as
it provides suspend protection for all RTCs that use rtc_update_irq.

BUG=chromium-os:36570
TEST=Fire wakealarm, check wakeup_count for increase:
  cat /sys/power/wakeup_count
  echo +1 >| /sys/class/rtc/rtc0/wakealarm
  sleep 1
  cat /sys/power/wakeup_count

Change-Id: I7dfc88bf6f95d0c5916b7e6ba751a56c62b5b82d
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl>
Signed-off-by: Michael Spang <spang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/38480
Reviewed-by: Grant Grundler <grundler@chromium.org>
Reviewed-by: Jon Kliegman <kliegs@chromium.org>
drivers/rtc/interface.c

index eb415bd7649418f1d91b5c45b98fe9411f5171d3..9592b936b71bca1987d19aceba0f6e8b20b165b9 100644 (file)
@@ -582,6 +582,7 @@ enum hrtimer_restart rtc_pie_update_irq(struct hrtimer *timer)
 void rtc_update_irq(struct rtc_device *rtc,
                unsigned long num, unsigned long events)
 {
+       pm_stay_awake(rtc->dev.parent);
        schedule_work(&rtc->irqwork);
 }
 EXPORT_SYMBOL_GPL(rtc_update_irq);
@@ -844,6 +845,7 @@ void rtc_timer_do_work(struct work_struct *work)
 
        mutex_lock(&rtc->ops_lock);
 again:
+       pm_relax(rtc->dev.parent);
        __rtc_read_time(rtc, &tm);
        now = rtc_tm_to_ktime(tm);
        while ((next = timerqueue_getnext(&rtc->timerqueue))) {