diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2015-11-06 17:37:56 +0100 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2016-01-11 20:19:54 +0100 |
commit | fbbf53f70225c82ba877de780486be5bc81b29e2 (patch) | |
tree | db1b469aefb12d9df8425d9b2450970becbcccb1 /drivers | |
parent | c60faa3afad0e926e63a39894489b64e9a8165df (diff) | |
download | linux-fbbf53f70225c82ba877de780486be5bc81b29e2.tar.bz2 |
rtc: pcf8523: refuse to write dates later than 2099
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önig <u.kleine-koenig@pengutronix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/rtc/rtc-pcf8523.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c index e7ebcc0b7e59..988566caaaa6 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, struct rtc_time *tm) u8 regs[8]; int err; + /* + * 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=0x00 (and the out-of-spec + * YEAR=0xa0) as a leap year, but 2100 isn't. + */ + if (tm->tm_year < 100 || tm->tm_year >= 200) + return -EINVAL; + err = pcf8523_stop_rtc(client); if (err < 0) return err; |