Skip to contentSkip to conversation

rtc: fix rtc_time64_to_tm for 3477

PATCH New Alexandre Belloni 1 participant 1 message Feb 28, 2018 Real time clock (RTC)

lore
Share & tools
lore

Alexandre Belloni

author maintainer
#0 lore raw

PATCH 1/1 rtc: fix rtc_time64_to_tm for 3477

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.

---
 drivers/rtc/rtc-lib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/rtc/rtc-lib.c +1 -1
index ad5bb21908e5..4a3c0f3aab14 100644
@@ -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);
 	}
Signature · 1 line
2.16.2