Skip to content

Commit

Permalink
rtc_time_to_tm: fix signed/unsigned arithmetic
Browse files Browse the repository at this point in the history
commit 945185a ("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>
Cc: <stable@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Jan Altenberg authored and Linus Torvalds committed Sep 3, 2008
1 parent b4a49b1 commit 73442da
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/rtc/rtc-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ EXPORT_SYMBOL(rtc_year_days);
*/
void rtc_time_to_tm(unsigned long time, struct rtc_time *tm)
{
unsigned int days, month, year;
unsigned int month, year;
int days;

days = time / 86400;
time -= days * 86400;
time -= (unsigned int) days * 86400;

/* day of the week, 1970-01-01 was a Thursday */
tm->tm_wday = (days + 4) % 7;
Expand Down

0 comments on commit 73442da

Please sign in to comment.