[PATCH] rtc-s3c.c: fix time setting checks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Fix the checking of the range for the year when
setting time with the S3C24XX RTC driver

Signed-off-by: Ben Dooks <[email protected]>

diff -urpN -X ../dontdiff linux-2.6.18-rc4-all1/drivers/rtc/rtc-s3c.c linux-2.6.18-rc4-all2/drivers/rtc/rtc-s3c.c
--- linux-2.6.18-rc4-all1/drivers/rtc/rtc-s3c.c	2006-08-14 09:04:57.000000000 +0100
+++ linux-2.6.18-rc4-all2/drivers/rtc/rtc-s3c.c	2006-08-14 09:59:47.000000000 +0100
@@ -11,6 +11,8 @@
  * S3C2410/S3C2440/S3C24XX Internal RTC Driver
 */
 
+//B#define DEBUG
+
 #include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/string.h>
@@ -153,24 +155,25 @@ static int s3c_rtc_gettime(struct device
 static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
 {
 	void __iomem *base = s3c_rtc_base;
+	int year = tm->tm_year - 100;
+
+	pr_debug("set time %02d.%02d.%02d %02d/%02d/%02d\n",
+		 tm->tm_year, tm->tm_mon, tm->tm_mday,
+		 tm->tm_hour, tm->tm_min, tm->tm_sec);
 
-	/* the rtc gets round the y2k problem by just not supporting it */
+	/* we get around y2k by simply not supporting it */
 
-	if (tm->tm_year > 100) {
+	if (year < 0 || year >= 100) {
 		dev_err(dev, "rtc only supports 100 years\n");
 		return -EINVAL;
 	}
 
-	pr_debug("set time %02d.%02d.%02d %02d/%02d/%02d\n",
-		 tm->tm_year, tm->tm_mon, tm->tm_mday,
-		 tm->tm_hour, tm->tm_min, tm->tm_sec);
-
 	writeb(BIN2BCD(tm->tm_sec),  base + S3C2410_RTCSEC);
 	writeb(BIN2BCD(tm->tm_min),  base + S3C2410_RTCMIN);
 	writeb(BIN2BCD(tm->tm_hour), base + S3C2410_RTCHOUR);
 	writeb(BIN2BCD(tm->tm_mday), base + S3C2410_RTCDATE);
 	writeb(BIN2BCD(tm->tm_mon + 1), base + S3C2410_RTCMON);
-	writeb(BIN2BCD(tm->tm_year - 100), base + S3C2410_RTCYEAR);
+	writeb(BIN2BCD(year), base + S3C2410_RTCYEAR);
 
 	return 0;
 }
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux