diff options
author | Stefan Christ <s.christ@phytec.de> | 2016-03-15 14:22:26 +0100 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2016-03-19 00:00:59 +0100 |
commit | bcebd81d00a062af5a4cf900b08c8ca22a26d52f (patch) | |
tree | ecb5898faad1ad7c9db3b4ada06d28ed5ef7033e /drivers/rtc/rtc-m41t80.c | |
parent | ae6e00b4c01f701a9a268adf35371c018396cd05 (diff) | |
download | linux-stable-bcebd81d00a062af5a4cf900b08c8ca22a26d52f.tar.gz linux-stable-bcebd81d00a062af5a4cf900b08c8ca22a26d52f.tar.bz2 linux-stable-bcebd81d00a062af5a4cf900b08c8ca22a26d52f.zip |
rtc: m41t80: avoid out of range year values
Avoid saving an out of range year value to the RTC. Reading that value
from the RTC again returns a totally wrong time value. For Example
$ timedatectl set-ntp no
$ timedatectl set-time "1990-01-01 12:12:00"
# Reboot
rtc-m41t80 0-0068: setting system clock to 2090-01-01 12:12:35 UTC (3786955955)
Signed-off-by: Stefan Christ <s.christ@phytec.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers/rtc/rtc-m41t80.c')
-rw-r--r-- | drivers/rtc/rtc-m41t80.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c index a82937e2f824..d107a8e72a7d 100644 --- a/drivers/rtc/rtc-m41t80.c +++ b/drivers/rtc/rtc-m41t80.c @@ -176,7 +176,13 @@ static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm) bin2bcd(tm->tm_mday) | (buf[M41T80_REG_DAY] & ~0x3f); buf[M41T80_REG_MON] = bin2bcd(tm->tm_mon + 1) | (buf[M41T80_REG_MON] & ~0x1f); + /* assume 20YY not 19YY */ + if (tm->tm_year < 100 || tm->tm_year > 199) { + dev_err(&client->dev, "Year must be between 2000 and 2099. It's %d.\n", + tm->tm_year + 1900); + return -EINVAL; + } buf[M41T80_REG_YEAR] = bin2bcd(tm->tm_year % 100); if (i2c_transfer(client->adapter, msgs, 1) != 1) { |