Skip to content

Commit

Permalink
rtc: pcf85063: fix year range
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
alexandrebelloni committed Jul 19, 2016
1 parent bb9dbb0 commit c421ce7
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions drivers/rtc/rtc-pcf85063.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ static int pcf85063_stop_clock(struct i2c_client *client, u8 *ctrl1)
return 0;
}

/*
* In the routines that deal directly with the pcf85063 hardware, we use
* rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
*/
static int pcf85063_get_datetime(struct i2c_client *client, struct rtc_time *tm)
{
int rc;
Expand Down Expand Up @@ -90,8 +86,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);
}
Expand All @@ -101,6 +96,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
Expand All @@ -125,7 +123,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
Expand Down

0 comments on commit c421ce7

Please sign in to comment.