[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20160831225929.20336-1-gabriele.mzt@gmail.com>
Date: Thu, 1 Sep 2016 00:59:29 +0200
From: Gabriele Mazzotta <gabriele.mzt@...il.com>
To: a.zummo@...ertech.it, alexandre.belloni@...e-electrons.com
Cc: rtc-linux@...glegroups.com, linux-kernel@...r.kernel.org,
Gabriele Mazzotta <gabriele.mzt@...il.com>
Subject: [PATCH] rtc-cmos: Reject unsupported alarm values
Return an error if the user tries to set an alarm that isn't
supported by the hardware.
Signed-off-by: Gabriele Mazzotta <gabriele.mzt@...il.com>
---
drivers/rtc/rtc-cmos.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index 4cdb335..b3f9298 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -336,6 +336,26 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
if (!is_valid_irq(cmos->irq))
return -EIO;
+ if (!cmos->mon_alrm || !cmos->day_alrm) {
+ struct rtc_time now;
+ time64_t t_now;
+ time64_t t_alrm;
+
+ cmos_read_time(dev, &now);
+ t_now = rtc_tm_to_time64(&now);
+ t_alrm = rtc_tm_to_time64(&t->time);
+ if (!cmos->day_alrm && (t_alrm - t_now) > (24 * 60 * 60)) {
+ dev_err(dev,
+ "Alarms can be up to one day in the future\n");
+ return -EINVAL;
+ }
+ if (!cmos->mon_alrm && (t_alrm - t_now) > (31 * 24 * 60 * 60)) {
+ dev_err(dev,
+ "Alarms can be up to 31 days in the future\n");
+ return -EINVAL;
+ }
+ }
+
mon = t->time.tm_mon + 1;
mday = t->time.tm_mday;
hrs = t->time.tm_hour;
--
2.9.3
Powered by blists - more mailing lists