* [PATCH] rtc_time_to_tm: Fix signed / unsigned arithmetic
@ 2008-08-02 14:34 Jan Altenberg
0 siblings, 0 replies; only message in thread
From: Jan Altenberg @ 2008-08-02 14:34 UTC (permalink / raw)
To: Maciej W. Rozycki; +Cc: Linux Kernel list, stable, tglx
Hi all,
commit 945185a69daa457c4c5e46e47f4afad7dcea734f 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. See attached patch.
Signed-off-by: Jan Altenberg <jan.altenberg@linutronix.de>
---
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index 9f996ec..dd70bf7 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -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;
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2008-08-02 14:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-02 14:34 [PATCH] rtc_time_to_tm: Fix signed / unsigned arithmetic Jan Altenberg
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.