aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/interface.c
diff options
context:
space:
mode:
authorAlexandre Belloni <alexandre.belloni@bootlin.com>2018-02-17 14:58:40 +0100
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2018-03-17 14:20:54 +0100
commit71db049e7355f31604e2c04b6cabb71d02bd487d (patch)
tree19743f8478631b847a11cf09690a6b4f28927e76 /drivers/rtc/interface.c
parent236b7187034e87bd46eb535ab4f276267ef66ee4 (diff)
downloadlinux-71db049e7355f31604e2c04b6cabb71d02bd487d.tar.gz
rtc: Add RTC range
Add a way for drivers to inform the core of the supported date/time range. The core can then check whether the date/time or alarm is in the range before calling ->set_time, ->set_mmss or ->set_alarm. It returns -ERANGE when the time is out of range. Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Diffstat (limited to 'drivers/rtc/interface.c')
-rw-r--r--drivers/rtc/interface.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 7e253be19ba7e..c068daebeec28 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -70,6 +70,13 @@ int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
if (err != 0)
return err;
+ if (rtc->range_min != rtc->range_max) {
+ time64_t time = rtc_tm_to_time64(tm);
+
+ if (time < rtc->range_min || time > rtc->range_max)
+ return -ERANGE;
+ }
+
err = mutex_lock_interruptible(&rtc->ops_lock);
if (err)
return err;
@@ -374,6 +381,13 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
if (err != 0)
return err;
+ if (rtc->range_min != rtc->range_max) {
+ time64_t time = rtc_tm_to_time64(&alarm->time);
+
+ if (time < rtc->range_min || time > rtc->range_max)
+ return -ERANGE;
+ }
+
err = mutex_lock_interruptible(&rtc->ops_lock);
if (err)
return err;