From 381424fcbb7381ad1b449b2ca41d54614db2a059 Mon Sep 17 00:00:00 2001 From: Guixiong Wei Date: Mon, 13 Jul 2020 13:34:36 +0800 Subject: [PATCH] rtc: Disable alarm irq if alarm time is in the past If device is boot up by rtc alarm, the alarm irq will still be enabled and the alarm time is smaller than current rtc time before any alarm is set or canceled. If device is powered off now, it will boot up automatically as the alarm irq is enabled. So disable alarm irq if alarm is enabled and alarm time is in the past. Change-Id: I53dc7cdb1fa7c56eea07ed01d1f6cb63f0bb8a8d Signed-off-by: Guixiong Wei --- drivers/rtc/interface.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index 5c1378d2fab3..13751e3638c2 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -479,6 +479,14 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) } EXPORT_SYMBOL_GPL(rtc_set_alarm); +static void rtc_alarm_disable(struct rtc_device *rtc) +{ + if (!rtc->ops || !rtc->ops->alarm_irq_enable) + return; + + rtc->ops->alarm_irq_enable(rtc->dev.parent, false); +} + /* Called once per device from rtc_device_register */ int rtc_initialize_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) { @@ -506,7 +514,11 @@ int rtc_initialize_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) rtc->aie_timer.enabled = 1; timerqueue_add(&rtc->timerqueue, &rtc->aie_timer.node); trace_rtc_timer_enqueue(&rtc->aie_timer); + } else if (alarm->enabled && (rtc_tm_to_ktime(now) >= + rtc->aie_timer.node.expires)){ + rtc_alarm_disable(rtc); } + mutex_unlock(&rtc->ops_lock); return err; } @@ -827,15 +839,6 @@ static int rtc_timer_enqueue(struct rtc_device *rtc, struct rtc_timer *timer) return 0; } -static void rtc_alarm_disable(struct rtc_device *rtc) -{ - if (!rtc->ops || !rtc->ops->alarm_irq_enable) - return; - - rtc->ops->alarm_irq_enable(rtc->dev.parent, false); - trace_rtc_alarm_irq_enable(0, 0); -} - /** * rtc_timer_remove - Removes a rtc_timer from the rtc_device timerqueue * @rtc rtc device