summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Belloni <alexandre.belloni@bootlin.com>2018-06-06 00:09:14 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2018-08-06 17:24:30 +0300
commitaf1ecd4b5f740c30f7ed72bb8af0d7f74cc1b88d (patch)
tree9970e516b01f1affa5193dd44f8cbced21e71067
parent3231613224c076ed1f0984e382cbd2df0d64c260 (diff)
downloadlinux-af1ecd4b5f740c30f7ed72bb8af0d7f74cc1b88d.tar.xz
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 <alexandre.belloni@bootlin.com> Signed-off-by: Sasha Levin <alexander.levin@microsoft.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/rtc/interface.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index c2cf9485fe32..8c10f3db6336 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -349,6 +349,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;