From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] efi: loader: fix year and month reported by GetTime
Date: Tue, 25 Aug 2026 10:52:22 +0200 [thread overview]
Message-ID: <20260825085223.1311031-1-a.fatoum@pengutronix.de> (raw)
struct rtc_time follows the Linux convention: tm_year counts from 1900
and tm_mon is zero based. EFI_TIME on the other hand carries the full
year and a one based month.
efi_get_time_boottime() copied both fields over unchanged, so GetTime()
reported year 126 and month 6 for July 2026.
efi_set_time_boottime() has the mirrored problem. rtc_valid_tm() accepts
the result, since it only rejects tm_year below 70 and tm_mon of 12 or
more, so rtc_tm_to_time() goes on to compute
mktime(time->year + 1900, time->month + 1, ...) and the RTC is set
roughly 1900 years and one month ahead.
Convert in both directions.
Assisted-by: Codex:gpt-5.5
Fixes: 06947fd4664c ("efi: loader: add support for runtime services before ExitBootServices")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
efi/loader/runtime.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/efi/loader/runtime.c b/efi/loader/runtime.c
index f0fbd263fe55..024d402b3915 100644
--- a/efi/loader/runtime.c
+++ b/efi/loader/runtime.c
@@ -173,8 +173,8 @@ static efi_status_t EFIAPI efi_get_time_boottime(
}
memset(time, 0, sizeof(*time));
- time->year = tm.tm_year;
- time->month = tm.tm_mon;
+ time->year = tm.tm_year + 1900;
+ time->month = tm.tm_mon + 1;
time->day = tm.tm_mday;
time->hour = tm.tm_hour;
time->minute = tm.tm_min;
@@ -257,8 +257,8 @@ static efi_status_t EFIAPI efi_set_time_boottime(struct efi_time *time)
}
memset(&tm, 0, sizeof(tm));
- tm.tm_year = time->year;
- tm.tm_mon = time->month;
+ tm.tm_year = time->year - 1900;
+ tm.tm_mon = time->month - 1;
tm.tm_mday = time->day;
tm.tm_hour = time->hour;
tm.tm_min = time->minute;
--
2.47.3
next reply other threads:[~2026-08-25 8:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-25 8:52 Ahmad Fatoum [this message]
2026-08-28 13:03 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260825085223.1311031-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox