rtc: fix rtc_time64_to_tm for 3477
authorAlexandre Belloni <alexandre.belloni@bootlin.com>
Wed, 28 Feb 2018 21:50:53 +0000 (22:50 +0100)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Sat, 17 Mar 2018 13:20:50 +0000 (14:20 +0100)
The current correction for leap years will fail in 3477. 3476-12-31 being
3477-01-00 because this is 366 leap years after 1970 and 3477 isn't a leap
year.

Fix that by looping over until days is positive or zero.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-lib.c

index ad5bb21..4a3c0f3 100644 (file)
@@ -65,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);
        }