From: Alexandre Belloni Date: Tue, 5 Jun 2018 21:09:14 +0000 (+0200) Subject: rtc: ensure rtc_set_alarm fails when alarms are not supported X-Git-Tag: v4.9.117~124 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fda8caa9cb0c80deab362d73a8fd2cd322ce20fc;p=platform%2Fkernel%2Flinux-amlogic.git rtc: ensure rtc_set_alarm fails when alarms are not supported [ Upstream commit abfdff44bc38e9e2ef7929f633fb8462632299d4 ] When using RTC_ALM_SET or RTC_WKALM_SET with rtc_wkalrm.enabled not set, rtc_timer_enqueue() is not called and rtc_set_alarm() may succeed but the subsequent RTC_AIE_ON ioctl will fail. RTC_ALM_READ would also fail in that case. Ensure rtc_set_alarm() fails when alarms are not supported to avoid letting programs think the alarms are working for a particular RTC when they are not. Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c index 25cf3069e2e7..4131bfb2cc61 100644 --- a/drivers/rtc/interface.c +++ b/drivers/rtc/interface.c @@ -359,6 +359,11 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm) { int err; + if (!rtc->ops) + return -ENODEV; + else if (!rtc->ops->set_alarm) + return -EINVAL; + err = rtc_valid_tm(&alarm->time); if (err != 0) return err;