aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/interface.c
diff options
context:
space:
mode:
authorJohn Stultz <john.stultz@linaro.org>2011-03-29 21:00:27 -0400
committerJohn Stultz <john.stultz@linaro.org>2011-03-29 21:44:05 -0400
commitf6d5b33125c4fa63c16f7f54c533338c9695d82c (patch)
tree2aabfeb48759bf6122c100f6977c8d7ff80e0c0d /drivers/rtc/interface.c
parent0ce790e7d736cedc563e1fb4e998babf5a4dbc3d (diff)
RTC: Fix early irqs caused by calling rtc_set_alarm too early
When we register an rtc device at boot, we read the alarm value in hardware and set the rtc device's aie_timer to that value. The initial method to do this was to simply call rtc_set_alarm() with the value read from hardware. However, this may cause problems as rtc_set_alarm may enable interupts, and the RTC alarm might fire, which can cause invalid pointer dereferencing since the RTC registration is not complete. This patch solves the issue by initializing the rtc_device.aie_timer y hand via rtc_initialize_alarm(). This avoids any calls to the RTC hardware which might enable interrupts too early. CC: Thomas Gleixner <tglx@linutronix.de> CC: Alessandro Zummo <a.zummo@towertech.it> Reported-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Tested-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: John Stultz <john.stultz@linaro.org>
Diffstat (limited to 'drivers/rtc/interface.c')
-rw-r--r--drivers/rtc/interface.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 8ec6b069a7f5..b2fea80dfb65 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -375,6 +375,32 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
375} 375}
376EXPORT_SYMBOL_GPL(rtc_set_alarm); 376EXPORT_SYMBOL_GPL(rtc_set_alarm);
377 377
378/* Called once per device from rtc_device_register */
379int rtc_initialize_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
380{
381 int err;
382
383 err = rtc_valid_tm(&alarm->time);
384 if (err != 0)
385 return err;
386
387 err = mutex_lock_interruptible(&rtc->ops_lock);
388 if (err)
389 return err;
390
391 rtc->aie_timer.node.expires = rtc_tm_to_ktime(alarm->time);
392 rtc->aie_timer.period = ktime_set(0, 0);
393 if (alarm->enabled) {
394 rtc->aie_timer.enabled = 1;
395 timerqueue_add(&rtc->timerqueue, &rtc->aie_timer.node);
396 }
397 mutex_unlock(&rtc->ops_lock);
398 return err;
399}
400EXPORT_SYMBOL_GPL(rtc_initialize_alarm);
401
402
403
378int rtc_alarm_irq_enable(struct rtc_device *rtc, unsigned int enabled) 404int rtc_alarm_irq_enable(struct rtc_device *rtc, unsigned int enabled)
379{ 405{
380 int err = mutex_lock_interruptible(&rtc->ops_lock); 406 int err = mutex_lock_interruptible(&rtc->ops_lock);