From adf042f6c61e92c181171118768e4309d87146b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=BBygowski?= Date: Thu, 29 Feb 2024 11:50:58 +0100 Subject: lib/rtc: Fix off-by-one error in February day count in leap year MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The month argument passed to rtc_month_days is 0-based, not 1-based. This results in the RTC being reverted to the build date constantly on 29th February 2024. Change-Id: If451e3e3471fef0d429e255cf297050a525ca1a2 Signed-off-by: Michał Żygowski Reviewed-on: https://review.coreboot.org/c/coreboot/+/80790 Reviewed-by: Sean Rhodes Reviewed-by: Paul Menzel Reviewed-by: Felix Singer Reviewed-by: Werner Zeh Tested-by: build bot (Jenkins) Reviewed-by: Felix Held Reviewed-by: Michał Kopeć --- src/lib/rtc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/lib/rtc.c') diff --git a/src/lib/rtc.c b/src/lib/rtc.c index d15148024d..3eeac27665 100644 --- a/src/lib/rtc.c +++ b/src/lib/rtc.c @@ -126,7 +126,7 @@ static int rtc_month_days(unsigned int month, unsigned int year) { int month_days[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; - return month_days[month] + (LEAP_YEAR(year) && month == 2); + return month_days[month] + (LEAP_YEAR(year) && month == 1); } int rtc_invalid(const struct rtc_time *tm) -- cgit v1.2.3