summaryrefslogtreecommitdiffstats
path: root/drivers/rtc/interface.c
diff options
context:
space:
mode:
authorAlexandre Belloni <alexandre.belloni@bootlin.com>2018-02-17 08:58:40 -0500
committerAlexandre Belloni <alexandre.belloni@bootlin.com>2018-03-17 09:20:54 -0400
commit71db049e7355f31604e2c04b6cabb71d02bd487d (patch)
tree19743f8478631b847a11cf09690a6b4f28927e76 /drivers/rtc/interface.c
parent236b7187034e87bd46eb535ab4f276267ef66ee4 (diff)
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 7e253be19ba7..c068daebeec2 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)
70 if (err != 0) 70 if (err != 0)
71 return err; 71 return err;
72 72
73 if (rtc->range_min != rtc->range_max) {
74 time64_t time = rtc_tm_to_time64(tm);
75
76 if (time < rtc->range_min || time > rtc->range_max)
77 return -ERANGE;
78 }
79
73 err = mutex_lock_interruptible(&rtc->ops_lock); 80 err = mutex_lock_interruptible(&rtc->ops_lock);
74 if (err) 81 if (err)
75 return err; 82 return err;
@@ -374,6 +381,13 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
374 if (err != 0) 381 if (err != 0)
375 return err; 382 return err;
376 383
384 if (rtc->range_min != rtc->range_max) {
385 time64_t time = rtc_tm_to_time64(&alarm->time);
386
387 if (time < rtc->range_min || time > rtc->range_max)
388 return -ERANGE;
389 }
390
377 err = mutex_lock_interruptible(&rtc->ops_lock); 391 err = mutex_lock_interruptible(&rtc->ops_lock);
378 if (err) 392 if (err)
379 return err; 393 return err;