]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
rtc: Fix overflow when converting time64_t to rtc_time
authorBaolin Wang <baolin.wang@linaro.org>
Mon, 25 Dec 2017 11:10:37 +0000 (19:10 +0800)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Tue, 13 Feb 2018 20:30:28 +0000 (21:30 +0100)
If we convert one large time values to rtc_time, in the original formula
'days * 86400' can be overflowed in 'unsigned int' type to make the formula
get one incorrect remain seconds value. Thus we can use div_s64_rem()
function to avoid this situation.

Signed-off-by: Baolin Wang <baolin.wang@linaro.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-lib.c

index 1ae7da5cfc608f6c4bcb3764b00683e2a54b7919..ad5bb21908e532e30e883b2e16483de221a8fce2 100644 (file)
@@ -52,13 +52,11 @@ EXPORT_SYMBOL(rtc_year_days);
  */
 void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
 {
-       unsigned int month, year;
-       unsigned long secs;
+       unsigned int month, year, secs;
        int days;
 
        /* time must be positive */
-       days = div_s64(time, 86400);
-       secs = time - (unsigned int) days * 86400;
+       days = div_s64_rem(time, 86400, &secs);
 
        /* day of the week, 1970-01-01 was a Thursday */
        tm->tm_wday = (days + 4) % 7;