From: Jan Altenberg <jan.altenberg@linutronix.de>
To: "Maciej W. Rozycki" <macro@linux-mips.org>
Cc: Linux Kernel list <linux-kernel@vger.kernel.org>,
stable@kernel.org, tglx@linutronix.de
Subject: [PATCH] rtc_time_to_tm: Fix signed / unsigned arithmetic
Date: Sat, 02 Aug 2008 16:34:40 +0200 [thread overview]
Message-ID: <1217687680.3872.10.camel@bender> (raw)
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;
reply other threads:[~2008-08-02 14:39 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1217687680.3872.10.camel@bender \
--to=jan.altenberg@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=macro@linux-mips.org \
--cc=stable@kernel.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox