From: Dan Carpenter <dan.carpenter@oracle.com>
To: sasha.levin@oracle.com
Cc: rtc-linux@googlegroups.com
Subject: [rtc-linux] re: rtc: fix overflow and incorrect calculation in rtc_time64_to_tm
Date: Tue, 5 Jan 2016 12:57:59 +0300 [thread overview]
Message-ID: <20160105095758.GG23619@mwanda> (raw)
Hello Sasha Levin,
The patch cab572b82c4b: "rtc: fix overflow and incorrect calculation
in rtc_time64_to_tm" from Dec 3, 2015, leads to the following static
checker warning:
drivers/rtc/rtc-lib.c:72 rtc_time64_to_tm()
warn: unsigned 'days' is never less than zero.
drivers/rtc/rtc-lib.c
49 /*
50 * rtc_time_to_tm64 - Converts time64_t to rtc_time.
51 * Convert seconds since 01-01-1970 00:00:00 to Gregorian date.
52 */
53 void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
54 {
55 unsigned int month, year;
56 int secs;
57 unsigned long days;
^^^^^^^^^^^^^^^^^^^
58
59 /*
60 * time must be positive
61 * This will fail for 32bit platforms on January 21st 11761191
62 */
63 days = div_s64_rem(time, 86400, &secs);
64
65 /* day of the week, 1970-01-01 was a Thursday */
66 tm->tm_wday = (days + 4) % 7;
67
68 year = 1970 + days / 365;
69 days -= (year - 1970) * 365
70 + LEAPS_THRU_END_OF(year - 1)
71 - LEAPS_THRU_END_OF(1970 - 1);
72 if (days < 0) {
^^^^^^^^^
73 year -= 1;
74 days += 365 + is_leap_year(year);
75 }
regards,
dan carpenter
--
--
You received this message because you are subscribed to "rtc-linux".
Membership options at http://groups.google.com/group/rtc-linux .
Please read http://groups.google.com/group/rtc-linux/web/checklist
before submitting a driver.
---
You received this message because you are subscribed to the Google Groups "rtc-linux" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rtc-linux+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
reply other threads:[~2016-01-05 9:58 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=20160105095758.GG23619@mwanda \
--to=dan.carpenter@oracle.com \
--cc=rtc-linux@googlegroups.com \
--cc=sasha.levin@oracle.com \
/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