[tip: timers/ptp] vdso/gettimeofday: Introduce vdso_clockid_valid()
From: tip-bot2 for Thomas Weißschuh
Date: Mon Jul 07 2025 - 03:12:49 EST
The following commit has been merged into the timers/ptp branch of tip:
Commit-ID: b5df72706b044b30b17f5d623fe040b83e98be36
Gitweb: https://git.kernel.org/tip/b5df72706b044b30b17f5d623fe040b83e98be36
Author: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>
AuthorDate: Tue, 01 Jul 2025 10:58:01 +02:00
Committer: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
CommitterDate: Mon, 07 Jul 2025 08:58:52 +02:00
vdso/gettimeofday: Introduce vdso_clockid_valid()
Move the clock ID validation check into a common helper.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@xxxxxxxxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Link: https://lore.kernel.org/all/20250701-vdso-auxclock-v1-7-df7d9f87b9b8@xxxxxxxxxxxxx
---
lib/vdso/gettimeofday.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/lib/vdso/gettimeofday.c b/lib/vdso/gettimeofday.c
index c526653..215151b 100644
--- a/lib/vdso/gettimeofday.c
+++ b/lib/vdso/gettimeofday.c
@@ -71,6 +71,12 @@ static inline bool vdso_cycles_ok(u64 cycles)
}
#endif
+static __always_inline bool vdso_clockid_valid(clockid_t clock)
+{
+ /* Check for negative values or invalid clocks */
+ return likely((u32) clock < MAX_CLOCKS);
+}
+
#ifdef CONFIG_TIME_NS
#ifdef CONFIG_GENERIC_VDSO_DATA_STORE
@@ -268,8 +274,7 @@ __cvdso_clock_gettime_common(const struct vdso_time_data *vd, clockid_t clock,
const struct vdso_clock *vc = vd->clock_data;
u32 msk;
- /* Check for negative values or invalid clocks */
- if (unlikely((u32) clock >= MAX_CLOCKS))
+ if (!vdso_clockid_valid(clock))
return false;
/*
@@ -405,8 +410,7 @@ bool __cvdso_clock_getres_common(const struct vdso_time_data *vd, clockid_t cloc
u32 msk;
u64 ns;
- /* Check for negative values or invalid clocks */
- if (unlikely((u32) clock >= MAX_CLOCKS))
+ if (!vdso_clockid_valid(clock))
return false;
if (IS_ENABLED(CONFIG_TIME_NS) &&