From: Karl Mehltretter <kmehltretter@gmail.com>
To: John Stultz <jstultz@google.com>, Thomas Gleixner <tglx@kernel.org>
Cc: "Karl Mehltretter" <kmehltretter@gmail.com>,
"Stephen Boyd" <sboyd@kernel.org>,
"Miroslav Lichvar" <mlichvar@redhat.com>,
"Deepa Dinamani" <deepa.kernel@gmail.com>,
"Cassio Neri" <cassio.neri@gmail.com>,
"Thomas Weißschuh" <thomas.weissschuh@linutronix.de>,
"David Laight" <david.laight.linux@gmail.com>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 2/2] time/kunit: Add time64_to_tm() case beyond 32-bit day count
Date: Fri, 25 Sep 2026 18:57:02 +0200 [thread overview]
Message-ID: <20260925165702.51677-3-kmehltretter@gmail.com> (raw)
In-Reply-To: <20260925165702.51677-1-kmehltretter@gmail.com>
The existing date range test covers +/-80,000 years around the epoch,
far below the day count at which a 32-bit long wraps (2^31 days,
roughly 5.88 million years).
Add a case at exactly 2^31 days after the epoch. Without the preceding
fix a 32-bit kernel returns tm_year=-5879541 and wrong month, day,
day-of-year and weekday; with it the result matches 64-bit kernels.
Assisted-by: LLM
Reviewed-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
kernel/time/time_test.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/kernel/time/time_test.c b/kernel/time/time_test.c
index 1b99180da288..8b718767b3ba 100644
--- a/kernel/time/time_test.c
+++ b/kernel/time/time_test.c
@@ -87,8 +87,24 @@ static void time64_to_tm_test_date_range(struct kunit *test)
}
}
+static void time64_to_tm_test_wide_day_count(struct kunit *test)
+{
+ /* 2^31 days: the first count that does not fit in a 32-bit long. */
+ time64_t timestamp = (1LL << 31) * 86400;
+ struct tm result;
+
+ time64_to_tm(timestamp, 0, &result);
+
+ KUNIT_EXPECT_EQ(test, result.tm_year, 5879680);
+ KUNIT_EXPECT_EQ(test, result.tm_mon, 6);
+ KUNIT_EXPECT_EQ(test, result.tm_mday, 12);
+ KUNIT_EXPECT_EQ(test, result.tm_yday, 193);
+ KUNIT_EXPECT_EQ(test, result.tm_wday, 6);
+}
+
static struct kunit_case time_test_cases[] = {
KUNIT_CASE_SLOW(time64_to_tm_test_date_range),
+ KUNIT_CASE(time64_to_tm_test_wide_day_count),
{}
};
--
2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2026-09-25 16:57 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 16:57 [PATCH v2 0/2] time: Prevent time64_to_tm() day truncation on 32-bit Karl Mehltretter
2026-09-25 16:57 ` [PATCH v2 1/2] " Karl Mehltretter
2026-09-29 19:22 ` [tip: timers/core] " tip-bot2 for Karl Mehltretter
2026-09-25 16:57 ` Karl Mehltretter [this message]
2026-09-29 19:22 ` [tip: timers/core] time/kunit: Add time64_to_tm() case beyond 32-bit day count tip-bot2 for Karl Mehltretter
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=20260925165702.51677-3-kmehltretter@gmail.com \
--to=kmehltretter@gmail.com \
--cc=cassio.neri@gmail.com \
--cc=david.laight.linux@gmail.com \
--cc=deepa.kernel@gmail.com \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mlichvar@redhat.com \
--cc=sboyd@kernel.org \
--cc=tglx@kernel.org \
--cc=thomas.weissschuh@linutronix.de \
/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
all inboxes | Powered by JetHome®