diff mbox

rtc: rtc-isl1208: reject invalid dates

Message ID 20081217001559.29099.29300.stgit@i1501.lan.towertech.it
State Accepted, archived
Headers show

Commit Message

Alessandro Zummo Dec. 17, 2008, 12:15 a.m. UTC
From: Chris Elston <celston@katalix.com>

This patch for the rtc-isl1208 driver makes it reject
invalid dates. Please queue it for 2.6.28 if possible.

Signed-off-by: Chris Elston <celston@katalix.com>
[a.zummo@towertech.it: added comment explaining the check]
Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
Cc: Hebert Valerio Riedel <hvr@gnu.org>
---

 drivers/rtc/rtc-isl1208.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
-~----------~----~----~----~------~----~------~--~---

Comments

Andrew Morton Dec. 17, 2008, 10:48 p.m. UTC | #1
On Wed, 17 Dec 2008 01:15:59 +0100
Alessandro Zummo <a.zummo@towertech.it> wrote:

> From: Chris Elston <celston@katalix.com>
> 
> This patch for the rtc-isl1208 driver makes it reject
> invalid dates. Please queue it for 2.6.28 if possible.

um, OK.

> Signed-off-by: Chris Elston <celston@katalix.com>
> [a.zummo@towertech.it: added comment explaining the check]

(cool!)

> Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
> Cc: Hebert Valerio Riedel <hvr@gnu.org>
> ---
> 
>  drivers/rtc/rtc-isl1208.c |    7 +++++++
>  1 files changed, 7 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
> index 2cd77ab..054e052 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;

but I'm wondering why this is considered sufficiently serious to be a
2.6.28 thing?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
-~----------~----~----~----~------~----~------~--~---
Alessandro Zummo Dec. 18, 2008, 12:31 a.m. UTC | #2
On Wed, 17 Dec 2008 14:48:34 -0800
Andrew Morton <akpm@linux-foundation.org> wrote:

> > +
> >  	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;
> 
> but I'm wondering why this is considered sufficiently serious to be a
> 2.6.28 thing?

 well, it could cause a bad date to be written.. not so serious
 maybe, but shouldn't harm either.. so if possible we can have a fix earlier
 in the kernel, otherwise just queue it for the next window.
diff mbox

Patch

diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
index 2cd77ab..054e052 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;