Skip to content

Commit f0414c1

Browse files
Colin Ian Kinggregkh
authored andcommitted
rtc: interface: ignore expired timers when enqueuing new timers
commit 2b2f5ff00f63847d95adad6289bd8b05f5983dd5 upstream. 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> Cc: Sumit Semwal <sumit.semwal@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a82ac39 commit f0414c1

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

drivers/rtc/interface.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,23 @@ EXPORT_SYMBOL_GPL(rtc_irq_set_freq);
748748
*/
749749
static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer)
750750
{
751+
struct timerqueue_node *next = timerqueue_getnext(&rtc->timerqueue);
752+
struct rtc_time tm;
753+
ktime_t now;
754+
751755
timer->enabled = 1;
756+
__rtc_read_time(rtc, &tm);
757+
now = rtc_tm_to_ktime(tm);
758+
759+
/* Skip over expired timers */
760+
while (next) {
761+
if (next->expires.tv64 >= now.tv64)
762+
break;
763+
next = timerqueue_iterate_next(next);
764+
}
765+
752766
timerqueue_add(&rtc->timerqueue, &timer->node);
753-
if (&timer->node == timerqueue_getnext(&rtc->timerqueue)) {
767+
if (!next) {
754768
struct rtc_wkalrm alarm;
755769
int err;
756770
alarm.time = rtc_ktime_to_tm(timer->node.expires);

0 commit comments

Comments
 (0)