[PATCH v2] timekeeping: Always initialize use_nsecs when querying time from phc drivers
From: Markus Blöchl
Date: Sun Jul 20 2025 - 09:56:18 EST
Most drivers only populate the fields cycles and cs_id in their
get_time_fn() callback for get_device_system_crosststamp() unless
they explicitly provide nanosecond values.
When this new use_nsecs field was added and used most drivers did not
care.
Clock sources other than CSID_GENERIC could then get converted in
convert_base_to_cs() based on an uninitialized use_nsecs which usually
results in -EINVAL during the following range check.
Pass in a fully initialized system_counterval_t.
Fixes: 6b2e29977518 ("timekeeping: Provide infrastructure for converting to/from a base clock")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Markus Blöchl <markus@xxxxxxxxx>
---
Changes in v2:
- Initialize entire system_counterval_t, not just use_nsecs
- Only initialize system_counterval_t once during instantiation instead
of every iteration.
- Link to v1: https://lore.kernel.org/lkml/txyrr26hxe3xpq3ebqb5ewkgvhvp7xalotaouwludjtjifnah2@7tmgczln4aoo/
---
kernel/time/timekeeping.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index a009c91f7b05fcb433073862a1b1a3de0345bffe..83c65f3afccaacff7a2e53e62f32657c201fbc8c 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1256,7 +1256,7 @@ int get_device_system_crosststamp(int (*get_time_fn)
struct system_time_snapshot *history_begin,
struct system_device_crosststamp *xtstamp)
{
- struct system_counterval_t system_counterval;
+ struct system_counterval_t system_counterval = {};
struct timekeeper *tk = &tk_core.timekeeper;
u64 cycles, now, interval_start;
unsigned int clock_was_set_seq = 0;
---
base-commit: f4a40a4282f467ec99745c6ba62cb84346e42139
change-id: 20250720-timekeeping_uninit_crossts-c130ee69fb1e
Best regards,
--
Markus Blöchl <markus@xxxxxxxxx>