[PATCH] RTC: rtc_time_to_tm: use unsigned arithmetic

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Maciej W. Rozycki
Date: Tuesday, May 6, 2008 - 3:31 pm

The input argument to rtc_time_to_tm() is unsigned as well as are members
of the output structure.  However signed arithmetic is used within for
calculations leading to incorrect results for input values outside the
signed positive range.  If this happens the time of day returned is out of
range.

 Found the problem when fiddling with the RTC and the driver where year
was set to an unexpectedly large value like 2070, e.g.:

rtc0: setting system clock to 2070-01-01 1193046:71582832:26 UTC (3155760954)

while it should be:

rtc0: setting system clock to 2070-01-01 00:15:54 UTC (3155760954)

Changing types to unsigned fixes the problem.

Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org>
---
 Tested on 64-bit MIPS.  Please apply.

  Maciej

patch-2.6.26-rc1-20080505-rtc-time-unsigned-11
diff -up --recursive --new-file linux-2.6.26-rc1-20080505.macro/drivers/rtc/rtc-lib.c linux-2.6.26-rc1-20080505/drivers/rtc/rtc-lib.c
--- linux-2.6.26-rc1-20080505.macro/drivers/rtc/rtc-lib.c	2007-07-10 04:56:26.000000000 +0000
+++ linux-2.6.26-rc1-20080505/drivers/rtc/rtc-lib.c	2008-05-05 02:37:38.000000000 +0000
@@ -51,7 +51,7 @@ EXPORT_SYMBOL(rtc_year_days);
  */
 void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
 {
-	register int days, month, year;
+	register unsigned int days, month, year;
 
 	days = time / 86400;
 	time -= days * 86400;
--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH] RTC: rtc_time_to_tm: use unsigned arithmetic, Maciej W. Rozycki, (Tue May 6, 3:31 pm)
Re: [PATCH] RTC: rtc_time_to_tm: use unsigned arithmetic, Dmitri Vorobiev, (Tue May 6, 3:50 pm)
Re: [PATCH] RTC: rtc_time_to_tm: use unsigned arithmetic, Maciej W. Rozycki, (Tue May 6, 6:11 pm)