[tip: timers/core] time/kunit: Document handling of negative years of is_leap()

tip-bot2 for Mark Brown posted 1 patch 4 days, 22 hours ago
kernel/time/time_test.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[tip: timers/core] time/kunit: Document handling of negative years of is_leap()
Posted by tip-bot2 for Mark Brown 4 days, 22 hours ago
The following commit has been merged into the timers/core branch of tip:

Commit-ID:     24989330fb99189cf9ec4accef6ac81c7b1c31f7
Gitweb:        https://git.kernel.org/tip/24989330fb99189cf9ec4accef6ac81c7b1c31f7
Author:        Mark Brown <broonie@kernel.org>
AuthorDate:    Fri, 30 Jan 2026 19:48:35 
Committer:     Thomas Gleixner <tglx@kernel.org>
CommitterDate: Mon, 02 Feb 2026 12:37:54 +01:00

time/kunit: Document handling of negative years of is_leap()

The code local is_leap() helper was tried to be replaced by the RTC
is_leap_year() function. Unfortunately the two aren't exactly equivalent,
as the kunit variant uses a signed value for the year and the RTC an
unsigned one.

Since the KUnit tests cover a 16000 year range around the epoch they use
year values that are very comfortably negative and hence get mishandled
when passed into is_leap_year().

The change was reverted, so add a comment which prevents further attempts
to do so.

[ tglx: Adapted to the revert ]

Signed-off-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Link: https://patch.msgid.link/20260130-kunit-fix-leap-year-v1-1-92ddf55dffd7@kernel.org
---
 kernel/time/time_test.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/kernel/time/time_test.c b/kernel/time/time_test.c
index 2889763..1b99180 100644
--- a/kernel/time/time_test.c
+++ b/kernel/time/time_test.c
@@ -4,7 +4,9 @@
 #include <linux/time.h>
 
 /*
- * Traditional implementation of leap year evaluation.
+ * Traditional implementation of leap year evaluation, but note that long
+ * is a signed type and the tests do cover negative year values. So this
+ * can't use the is_leap_year() helper from rtc.h.
  */
 static bool is_leap(long year)
 {