Merge tag 'drm-next-2018-06-11' of git://anongit.freedesktop.org/drm/drm
[linux-2.6-microblaze.git] / drivers / rtc / rtc-lib.c
index 1ae7da5..4a3c0f3 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;
@@ -67,7 +65,7 @@ void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
        days -= (year - 1970) * 365
                + LEAPS_THRU_END_OF(year - 1)
                - LEAPS_THRU_END_OF(1970 - 1);
-       if (days < 0) {
+       while (days < 0) {
                year -= 1;
                days += 365 + is_leap_year(year);
        }