[PATCH] rtc: mcfrtc: fix leap year calculation using wrong variable
Naveen Kumar Chaudhary
naveen.osdev at gmail.com
Wed Jun 10 19:08:40 CEST 2026
The leap year check in rtc_set() passes the loop variable 'i' (month
index, always 1 when the condition is true) to isleap() instead of the
actual year. Since isleap(1) is always false, February 29th is never
accounted for when computing the day count, resulting in the RTC being
set one day behind for any date after February in a leap year.
Pass tmp->tm_year to isleap() so the leap day is correctly included.
Fixes: 8e585f02f82 ("MCF5301x and MCF5445x RTC")
Signed-off-by: Naveen Kumar Chaudhary <naveen.osdev at gmail.com>
---
Hi,
Though this seems to be pretty old driver, but even if its EOL, as
long as its in the repo, its prone to be re-used and infect. Hence,
lets close the bug.
Regards,
Naveen
drivers/rtc/mcfrtc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/rtc/mcfrtc.c b/drivers/rtc/mcfrtc.c
index 9708971c5c4..23ffb2b31a1 100644
--- a/drivers/rtc/mcfrtc.c
+++ b/drivers/rtc/mcfrtc.c
@@ -73,7 +73,7 @@ int rtc_set(struct rtc_time *tmp)
days += month_days[i];
if (i == 1)
- days += isleap(i);
+ days += isleap(tmp->tm_year);
}
days += tmp->tm_mday - 1;
--
2.43.0
More information about the U-Boot
mailing list