aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-lib.c
diff options
context:
space:
mode:
authorMaciej W. Rozycki <macro@linux-mips.org>2008-05-12 17:02:24 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-05-13 11:02:25 -0400
commit945185a69daa457c4c5e46e47f4afad7dcea734f (patch)
tree688be6d624632b5538c925ac278511ea2aa79f02 /drivers/rtc/rtc-lib.c
parentf38c84312748de9d04562c12af57080c6901f931 (diff)
rtc: rtc_time_to_tm: use unsigned arithmetic
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. [akpm@linux-foundation.org: remove old-fashioned `register' keyword] Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org> Cc: Alessandro Zummo <a.zummo@towertech.it> Cc: David Brownell <david-b@pacbell.net> Cc: Dmitri Vorobiev <dmitri.vorobiev@gmail.com> Cc: <stable@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc/rtc-lib.c')
-rw-r--r--drivers/rtc/rtc-lib.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index ba795a4db1e9..9f996ec881ce 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -51,7 +51,7 @@ EXPORT_SYMBOL(rtc_year_days);
51 */ 51 */
52void rtc_time_to_tm(unsigned long time, struct rtc_time *tm) 52void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
53{ 53{
54 register int days, month, year; 54 unsigned int days, month, year;
55 55
56 days = time / 86400; 56 days = time / 86400;
57 time -= days * 86400; 57 time -= days * 86400;