aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc
diff options
context:
space:
mode:
authorAlexandre Belloni <alexandre.belloni@free-electrons.com>2016-07-18 05:08:59 -0400
committerAlexandre Belloni <alexandre.belloni@free-electrons.com>2016-07-19 13:11:12 -0400
commitc421ce7265ce0280453811f4447ede754ebe7e66 (patch)
treec9696649f5eb6ba8ede13e2cbe94b9beeead97cc /drivers/rtc
parentbb9dbb01bef96f058f55b984e43a33894c624065 (diff)
rtc: pcf85063: fix year range
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>
Diffstat (limited to 'drivers/rtc')
-rw-r--r--drivers/rtc/rtc-pcf85063.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/drivers/rtc/rtc-pcf85063.c b/drivers/rtc/rtc-pcf85063.c
index e8ddbb359d11..437638eb68a7 100644
--- a/drivers/rtc/rtc-pcf85063.c
+++ b/drivers/rtc/rtc-pcf85063.c
@@ -55,10 +55,6 @@ static int pcf85063_stop_clock(struct i2c_client *client, u8 *ctrl1)
55 return 0; 55 return 0;
56} 56}
57 57
58/*
59 * In the routines that deal directly with the pcf85063 hardware, we use
60 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
61 */
62static int pcf85063_get_datetime(struct i2c_client *client, struct rtc_time *tm) 58static int pcf85063_get_datetime(struct i2c_client *client, struct rtc_time *tm)
63{ 59{
64 int rc; 60 int rc;
@@ -90,8 +86,7 @@ static int pcf85063_get_datetime(struct i2c_client *client, struct rtc_time *tm)
90 tm->tm_wday = regs[4] & 0x07; 86 tm->tm_wday = regs[4] & 0x07;
91 tm->tm_mon = bcd2bin(regs[5] & 0x1F) - 1; /* rtc mn 1-12 */ 87 tm->tm_mon = bcd2bin(regs[5] & 0x1F) - 1; /* rtc mn 1-12 */
92 tm->tm_year = bcd2bin(regs[6]); 88 tm->tm_year = bcd2bin(regs[6]);
93 if (tm->tm_year < 70) 89 tm->tm_year += 100;
94 tm->tm_year += 100; /* assume we are in 1970...2069 */
95 90
96 return rtc_valid_tm(tm); 91 return rtc_valid_tm(tm);
97} 92}
@@ -101,6 +96,9 @@ static int pcf85063_set_datetime(struct i2c_client *client, struct rtc_time *tm)
101 int rc; 96 int rc;
102 u8 regs[8]; 97 u8 regs[8];
103 98
99 if ((tm->tm_year < 100) || (tm->tm_year > 199))
100 return -EINVAL;
101
104 /* 102 /*
105 * to accurately set the time, reset the divider chain and keep it in 103 * to accurately set the time, reset the divider chain and keep it in
106 * reset state until all time/date registers are written 104 * reset state until all time/date registers are written
@@ -125,7 +123,7 @@ static int pcf85063_set_datetime(struct i2c_client *client, struct rtc_time *tm)
125 regs[5] = bin2bcd(tm->tm_mon + 1); 123 regs[5] = bin2bcd(tm->tm_mon + 1);
126 124
127 /* year and century */ 125 /* year and century */
128 regs[6] = bin2bcd(tm->tm_year % 100); 126 regs[6] = bin2bcd(tm->tm_year - 100);
129 127
130 /* 128 /*
131 * after all time/date registers are written, let the 'address auto 129 * after all time/date registers are written, let the 'address auto