From cc6c2ca30074a0274c05dd3212c741a550f0d3c2 Mon Sep 17 00:00:00 2001 From: Chris Elston Date: Tue, 23 Dec 2008 13:57:10 -0800 Subject: rtc: rtc-isl1208: reject invalid dates This patch for the rtc-isl1208 driver makes it reject invalid dates. Signed-off-by: Chris Elston [a.zummo@towertech.it: added comment explaining the check] Signed-off-by: Alessandro Zummo Cc: Hebert Valerio Riedel Cc: David Brownell Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/rtc/rtc-isl1208.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers') diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c index 2cd77ab8fc6..054e05294af 100644 --- a/drivers/rtc/rtc-isl1208.c +++ b/drivers/rtc/rtc-isl1208.c @@ -328,6 +328,13 @@ isl1208_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm) int sr; u8 regs[ISL1208_RTC_SECTION_LEN] = { 0, }; + /* The clock has an 8 bit wide bcd-coded register (they never learn) + * for the year. tm_year is an offset from 1900 and we are interested + * in the 2000-2099 range, so any value less than 100 is invalid. + */ + if (tm->tm_year < 100) + return -EINVAL; + regs[ISL1208_REG_SC] = bin2bcd(tm->tm_sec); regs[ISL1208_REG_MN] = bin2bcd(tm->tm_min); regs[ISL1208_REG_HR] = bin2bcd(tm->tm_hour) | ISL1208_REG_HR_MIL; -- cgit v1.2.3