Skip to content

Commit

Permalink
rtc: Avoid setting alarm to a time in the past
Browse files Browse the repository at this point in the history
In some cases at boot up, the RTC alarm may be set in the past,
but still have the enabled flag on. This was causing problems,
because we would then enqueue the alarm into the timerqueue,
but it would never fire. This would clog up the timerqueue
and keep other alarms from working.

The fix is to check the alarm against the current rtc time at
boot and avoid enqueueing the alarm if it is in the past.

Reported-by: NeilBrown <neilb@suse.de>
Tested-by: NeilBrown <neilb@suse.de>
Tested-by: Sander Eikelenboom <linux@eikelenboom.it>
Signed-off-by: John Stultz <john.stultz@linaro.org>
  • Loading branch information
John Stultz committed Jan 27, 2012
1 parent a99cbf6 commit bd729d7
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion drivers/rtc/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,18 +380,27 @@ EXPORT_SYMBOL_GPL(rtc_set_alarm);
int rtc_initialize_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
{
int err;
struct rtc_time now;

err = rtc_valid_tm(&alarm->time);
if (err != 0)
return err;

err = rtc_read_time(rtc, &now);
if (err)
return err;

err = mutex_lock_interruptible(&rtc->ops_lock);
if (err)
return err;

rtc->aie_timer.node.expires = rtc_tm_to_ktime(alarm->time);
rtc->aie_timer.period = ktime_set(0, 0);
if (alarm->enabled) {

/* Alarm has to be enabled & in the futrure for us to enqueue it */
if (alarm->enabled && (rtc_tm_to_ktime(now).tv64 <
rtc->aie_timer.node.expires.tv64)) {

rtc->aie_timer.enabled = 1;
timerqueue_add(&rtc->timerqueue, &rtc->aie_timer.node);
}
Expand Down

0 comments on commit bd729d7

Please sign in to comment.