[PATCH] rtc-s3c.c: fix time setting checks
authorBen Dooks <ben-linux@fluff.org>
Sun, 27 Aug 2006 08:23:27 +0000 (01:23 -0700)
committerLinus Torvalds <torvalds@g5.osdl.org>
Sun, 27 Aug 2006 18:01:28 +0000 (11:01 -0700)
Fix the year check on setting the time with the S3C24XX RTC driver.  Also
move the debug to before the set to see what is going on if it does fail.

Signed-off-by: Ben Dooks <ben-linux@fluff.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
drivers/rtc/rtc-s3c.c

index aacbfea9867873ed7258a27afed02ba0346857d1..2c7de79c83b9baa352769e7626bc06b27c8abb60 100644 (file)
@@ -153,24 +153,25 @@ static int s3c_rtc_gettime(struct device *dev, struct rtc_time *rtc_tm)
 static int s3c_rtc_settime(struct device *dev, struct rtc_time *tm)
 {
        void __iomem *base = s3c_rtc_base;
+       int year = tm->tm_year - 100;
 
-       /* the rtc gets round the y2k problem by just not supporting it */
+       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);
+
+       /* 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;
 }