]> git.karo-electronics.de Git - karo-tx-linux.git/commit
rtc_time_to_tm: fix signed/unsigned arithmetic
authorJan Altenberg <jan.altenberg@linutronix.de>
Wed, 3 Sep 2008 02:35:04 +0000 (02:35 +0000)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 8 Sep 2008 11:44:20 +0000 (04:44 -0700)
commitcd9295c8b95d690c47f5f0000e3128960de8cd8b
tree4b34a1543c804b1a7322e42b3cfa908b72ecb7fb
parentb6cdf4eeaf022b84c7d41cc8c1e20c2a0be7100d
rtc_time_to_tm: fix signed/unsigned arithmetic

commit 73442daf2ea85e2a779396b76b1a39b10188ecb5 upstream

commit 945185a69daa457c4c5e46e47f4afad7dcea734f ("rtc: rtc_time_to_tm: use
unsigned arithmetic") changed the some types in rtc_time_to_tm() to
unsigned:

 void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
 {
-       register int days, month, year;
+       unsigned int days, month, year;

This doesn't work for all cases, because days is checked for < 0 later
on:

if (days < 0) {
year -= 1;
days += 365 + LEAP_YEAR(year);
}

I think the correct fix would be to keep days signed and do an appropriate
cast later on.

Signed-off-by: Jan Altenberg <jan.altenberg@linutronix.de>
Cc: 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>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/rtc/rtc-lib.c