aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/interface.c
diff options
context:
space:
mode:
authorColin Ian King <colin.king@canonical.com>2016-05-16 12:22:54 -0400
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>2016-06-04 09:43:22 -0400
commit2b2f5ff00f63847d95adad6289bd8b05f5983dd5 (patch)
treefd6c31f7d35b9c4b97554497028a06241469e9cb /drivers/rtc/interface.c
parent279da1495dae0d8ceee0cbe26187188ee27b7853 (diff)
rtc: interface: ignore expired timers when enqueuing new timers
This patch fixes a RTC wakealarm issue, namely, the event fires during hibernate and is not cleared from the list, causing hwclock to block. The current enqueuing does not trigger an alarm if any expired timers already exist on the timerqueue. This can occur when a RTC wake alarm is used to wake a machine out of hibernate and the resumed state has old expired timers that have not been removed from the timer queue. This fix skips over any expired timers and triggers an alarm if there are no pending timers on the timerqueue. Note that the skipped expired timer will get reaped later on, so there is no need to clean it up immediately. The issue can be reproduced by putting a machine into hibernate and waking it with the RTC wakealarm. Running the example RTC test program from tools/testing/selftests/timers/rtctest.c after the hibernate will block indefinitely. With the fix, it no longer blocks after the hibernate resume. BugLink: http://bugs.launchpad.net/bugs/1333569 Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers/rtc/interface.c')
-rw-r--r--drivers/rtc/interface.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 99475908e556..7cafd4d33ed3 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -758,9 +758,23 @@ EXPORT_SYMBOL_GPL(rtc_irq_set_freq);
758 */ 758 */
759static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer) 759static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer)
760{ 760{
761 struct timerqueue_node *next = timerqueue_getnext(&rtc->timerqueue);
762 struct rtc_time tm;
763 ktime_t now;
764
761 timer->enabled = 1; 765 timer->enabled = 1;
766 __rtc_read_time(rtc, &tm);
767 now = rtc_tm_to_ktime(tm);
768
769 /* Skip over expired timers */
770 while (next) {
771 if (next->expires.tv64 >= now.tv64)
772 break;
773 next = timerqueue_iterate_next(next);
774 }
775
762 timerqueue_add(&rtc->timerqueue, &timer->node); 776 timerqueue_add(&rtc->timerqueue, &timer->node);
763 if (&timer->node == timerqueue_getnext(&rtc->timerqueue)) { 777 if (!next) {
764 struct rtc_wkalrm alarm; 778 struct rtc_wkalrm alarm;
765 int err; 779 int err;
766 alarm.time = rtc_ktime_to_tm(timer->node.expires); 780 alarm.time = rtc_ktime_to_tm(timer->node.expires);