[rtc-linux] re: rtc: fix overflow and incorrect calculation in rtc_time64_to_tm

From: Dan Carpenter <hidden>
Date: 2016-01-05 09:58:10

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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help