]> git.baikalelectronics.ru Git - kernel.git/commitdiff
powerpc: Avoid giving out RTC dates below EPOCH
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>
Sun, 1 Nov 2009 19:11:03 +0000 (19:11 +0000)
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>
Thu, 5 Nov 2009 06:06:21 +0000 (17:06 +1100)
Doing so causes xtime to be negative which crashes the timekeeping
code in funny ways when doing suspend/resume

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
arch/powerpc/kernel/time.c

index 92dc844299b65ff5b7d934b14e4e110a6d956547..a136a11c490d0f36a9b32812132e682c38262f8f 100644 (file)
@@ -777,7 +777,7 @@ int update_persistent_clock(struct timespec now)
        return ppc_md.set_rtc_time(&tm);
 }
 
-void read_persistent_clock(struct timespec *ts)
+static void __read_persistent_clock(struct timespec *ts)
 {
        struct rtc_time tm;
        static int first = 1;
@@ -800,10 +800,23 @@ void read_persistent_clock(struct timespec *ts)
                return;
        }
        ppc_md.get_rtc_time(&tm);
+
        ts->tv_sec = mktime(tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
                            tm.tm_hour, tm.tm_min, tm.tm_sec);
 }
 
+void read_persistent_clock(struct timespec *ts)
+{
+       __read_persistent_clock(ts);
+
+       /* Sanitize it in case real time clock is set below EPOCH */
+       if (ts->tv_sec < 0) {
+               ts->tv_sec = 0;
+               ts->tv_nsec = 0;
+       }
+               
+}
+
 /* clocksource code */
 static cycle_t rtc_read(struct clocksource *cs)
 {