All of lore.kernel.org
 help / color / mirror / Atom feed
* [rtc-linux] re: rtc: fix overflow and incorrect calculation in rtc_time64_to_tm
@ 2016-01-05  9:57 Dan Carpenter
  0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2016-01-05  9:57 UTC (permalink / raw)
  To: sasha.levin; +Cc: rtc-linux

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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2016-01-05  9:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-05  9:57 [rtc-linux] re: rtc: fix overflow and incorrect calculation in rtc_time64_to_tm Dan Carpenter

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.