diff mbox

powerpc: Avoid giving out RTC dates below EPOCH

Message ID 1257138663.7907.32.camel@pasglop (mailing list archive)
State Accepted, archived
Headers show

Commit Message

Benjamin Herrenschmidt Nov. 2, 2009, 5:11 a.m. UTC
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>
---

Comments

Benjamin Herrenschmidt Nov. 2, 2009, 5:13 a.m. UTC | #1
On Mon, 2009-11-02 at 16:11 +1100, Benjamin Herrenschmidt wrote:
> 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>
> ---

> +void read_persistent_clock(struct timespec *ts)
> +{
> +	__read_persistent_clock(&ts);

Should read

+	__read_persistent_clock(ts);

Forgot a quilt ref ;-)

Cheers,
Ben.

> +	/* 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)
>  {
> 
> 
> 
> _______________________________________________
> Linuxppc-dev mailing list
> Linuxppc-dev@lists.ozlabs.org
> https://lists.ozlabs.org/listinfo/linuxppc-dev
diff mbox

Patch

diff --git a/arch/powerpc/kernel/time.c b/arch/powerpc/kernel/time.c
index 92dc844..6a7ce0e 100644
--- a/arch/powerpc/kernel/time.c
+++ b/arch/powerpc/kernel/time.c
@@ -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)
 {