[Question] About off-by-one error in tk_aux_sysfs_init() loop
From: Haofeng Li
Date: Sat Oct 11 2025 - 05:11:52 EST
Hi all,
While reviewing the timekeeping sysfs initialization code,
I noticed that in tk_aux_sysfs_init() the loop condition
i <= MAX_AUX_CLOCKS appears to iterate one more time than intended.
Code in tk_aux_sysfs_init():
for (int i = 0; i <= MAX_AUX_CLOCKS; i++) {
char id[2] = { [0] = '0' + i, };
struct kobject *clk = kobject_create_and_add(id, auxo);
// ...
}
With MAX_AUX_CLOCKS defined as 8, this loop runs 9 times (i = 0 to 8),
creating sysfs nodes for 9 auxiliary clocks. However, according
to the comments, the kernel only supports up to 8 auxiliary clocks.
This seems like an off-by-one error that could lead to creating one
more sysfs node than actually supported by the architecture constraints.
Would it make sense to change the loop condition to i < MAX_AUX_CLOCKS
to properly align with the intended 8-clock limit?
Thanks for your time and consideration.
Thanks,
Haofeng Li