linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc-cmos: Reject unsupported alarm values
@ 2016-08-31 22:59 Gabriele Mazzotta
  2016-08-31 23:41 ` Gabriele Mazzotta
  2016-09-02 19:55 ` [PATCH v2] " Gabriele Mazzotta
  0 siblings, 2 replies; 7+ messages in thread
From: Gabriele Mazzotta @ 2016-08-31 22:59 UTC (permalink / raw)
  To: a.zummo, alexandre.belloni; +Cc: rtc-linux, linux-kernel, Gabriele Mazzotta

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@gmail.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

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-10-19 14:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-31 22:59 [PATCH] rtc-cmos: Reject unsupported alarm values Gabriele Mazzotta
2016-08-31 23:41 ` Gabriele Mazzotta
2016-09-02 19:55 ` [PATCH v2] " Gabriele Mazzotta
2016-09-21 23:29   ` Alexandre Belloni
2016-09-22 19:47     ` Gabriele Mazzotta
2016-10-03 22:50   ` [PATCH v3] " Gabriele Mazzotta
2016-10-19  7:41     ` Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).