Linux RTC
 help / color / mirror / Atom feed
* [rtc-linux] [PATCH] rtc: pcf8523: refuse to write dates later than 2099
@ 2015-11-06 16:37 Uwe Kleine-König
  2015-11-24 23:35 ` [rtc-linux] " Alexandre Belloni
  0 siblings, 1 reply; 2+ messages in thread
From: Uwe Kleine-König @ 2015-11-06 16:37 UTC (permalink / raw)
  To: Alessandro Zummo, Alexandre Belloni; +Cc: rtc-linux, kernel

When the chip increments the YEAR register and it already holds
bin2bcd(99) it reads as 0 afterwards. With this behaviour the last valid
day (without trickery) that has a representation is 2099-12-31 23:59:59.
So refuse to write later dates.

Signed-off-by: Uwe Kleine-K=C3=B6nig <u.kleine-koenig@pengutronix.de>
---
Hello,

When setting the YEAR register to bin2bcd(100) =3D=3D 0xa0 it increments
just fine up to bin2bcd(159) =3D=3D 0xf9 but these values are forbidden in
the manual. But this doesn't help to expand (or shift) the range of
supported dates.

An alternative to this patch would be to save tm_year % 100 because
that's what happens when waiting long enough anyhow. Would that be
better? Do we already care at all for year-2100-problems?

Best regards
Uwe

 drivers/rtc/rtc-pcf8523.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c
index 4cdb64be061b..261d65e67c8b 100644
--- a/drivers/rtc/rtc-pcf8523.c
+++ b/drivers/rtc/rtc-pcf8523.c
@@ -219,6 +219,17 @@ static int pcf8523_rtc_set_time(struct device *dev, st=
ruct rtc_time *tm)
 	u8 regs[8];
 	int err;
=20
+	/*
+	 * The hardware can only store values between 0 and 99 in it's YEAR
+	 * register (with 99 overflowing to 0 on increment).
+	 * After 2100-02-28 we could start interpreting the year to be in the
+	 * interval [2100, 2199], but there is no path to switch in a smooth way
+	 * because the chip handles YEAR=3D0x00 (and the out-of-spec
+	 * YEAR=3D0xa0) as a leap year, but 2100 isn't.
+	 */
+	if (tm->tm_year < 100 || tm->tm_year >=3D 200)
+		return -EINVAL;
+
 	err =3D pcf8523_stop_rtc(client);
 	if (err < 0)
 		return err;
--=20
2.6.1

--=20
--=20
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---=20
You received this message because you are subscribed to the Google Groups "=
rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

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

end of thread, other threads:[~2015-11-24 23:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-06 16:37 [rtc-linux] [PATCH] rtc: pcf8523: refuse to write dates later than 2099 Uwe Kleine-König
2015-11-24 23:35 ` [rtc-linux] " Alexandre Belloni

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox