linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtc: pcf85063: fix year range
@ 2016-07-18  9:08 Alexandre Belloni
  0 siblings, 0 replies; only message in thread
From: Alexandre Belloni @ 2016-07-18  9:08 UTC (permalink / raw)
  To: Alessandro Zummo; +Cc: rtc-linux, linux-kernel, Alexandre Belloni

The year range is not validated properly

As the driver has been mainlined in 2014, it is not an issue to stop
handling dates between 1970 and 2000 with the benefit of handling dates up
to 2100.

Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
---
 drivers/rtc/rtc-pcf85063.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c
index e8ddbb359d11..f7d27b6857e6 100644
--- a/drivers/rtc/rtc-pcf85063.c
+++ b/drivers/rtc/rtc-pcf85063.c
@@ -57,7 +57,7 @@ static int pcf85063_stop_clock(struct i2c_client *client, u8 *ctrl1)
 
 /*
  * In the routines that deal directly with the pcf85063 hardware, we use
- * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
+ * rtc_time -- month 0-11, hour 0-23, yr = calendar year-100.
  */
 static int pcf85063_get_datetime(struct i2c_client *client, struct rtc_time *tm)
 {
@@ -90,8 +90,7 @@ static int pcf85063_get_datetime(struct i2c_client *client, struct rtc_time *tm)
 	tm->tm_wday = regs[4] & 0x07;
 	tm->tm_mon = bcd2bin(regs[5] & 0x1F) - 1; /* rtc mn 1-12 */
 	tm->tm_year = bcd2bin(regs[6]);
-	if (tm->tm_year < 70)
-		tm->tm_year += 100;	/* assume we are in 1970...2069 */
+	tm->tm_year += 100;
 
 	return rtc_valid_tm(tm);
 }
@@ -101,6 +100,9 @@ static int pcf85063_set_datetime(struct i2c_client *client, struct rtc_time *tm)
 	int rc;
 	u8 regs[8];
 
+	if ((tm->tm_year < 100) || (tm->tm_year > 199))
+		return -EINVAL;
+
 	/*
 	 * to accurately set the time, reset the divider chain and keep it in
 	 * reset state until all time/date registers are written
@@ -125,7 +127,7 @@ static int pcf85063_set_datetime(struct i2c_client *client, struct rtc_time *tm)
 	regs[5] = bin2bcd(tm->tm_mon + 1);
 
 	/* year and century */
-	regs[6] = bin2bcd(tm->tm_year % 100);
+	regs[6] = bin2bcd(tm->tm_year - 100);
 
 	/*
 	 * after all time/date registers are written, let the 'address auto
-- 
2.8.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-07-18  9:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-18  9:08 [PATCH] rtc: pcf85063: fix year range 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).