Re: [PATCH] clk: tenstorrent: Assign .num before accessing .hws

From: Gustavo A. R. Silva

Date: Mon Sep 07 2026 - 22:56:39 EST




On 9/6/26 05:48, Aamir Ahmed wrote:
Commit f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with
__counted_by") annotated the hws member of 'struct clk_hw_onecell_data'
with __counted_by, which informs the bounds sanitizer (UBSAN_BOUNDS)
about the number of elements in .hws[], so that it can warn when .hws[]
is accessed out of bounds. As noted in that change, the __counted_by
member must be initialized with the number of elements before the first
array access happens, otherwise there will be a warning from each access
prior to the initialization because the number of elements is zero.
This occurs in atlantis_prcm_clocks_register() due to .num being
assigned only after every clock has been stored in .hws[]. With
CONFIG_UBSAN_BOUNDS and a compiler that implements __counted_by (GCC
15.1+ or Clang 20.1+), this triggers an array-index-out-of-bounds report
during probe, and with CONFIG_UBSAN_TRAP the first store traps so the
clock provider never registers.

Move the .num initialization to right after the allocation.

Cc: stable@xxxxxxxxxxxxxxx
Fixes: 23c8ebc95284 ("clk: tenstorrent: Add Atlantis clock controller driver")
Assisted-by: LLM
Signed-off-by: Aamir Ahmed <elb12345@xxxxxxxxxxxxx>

LGTM:

Reviewed-by: Gustavo A. R. Silva <gustavoars@xxxxxxxxxx>

Also, see more comments below...

diff --git a/drivers/clk/tenstorrent/atlantis-prcm.c b/drivers/clk/tenstorrent/atlantis-prcm.c
index 6d4386eeb7d..a68534a295c 100644
--- a/drivers/clk/tenstorrent/atlantis-prcm.c
+++ b/drivers/clk/tenstorrent/atlantis-prcm.c
@@ -796,6 +796,8 @@ static int atlantis_prcm_clocks_register(struct device *dev,
if (!clk_data)
return -ENOMEM;
+ clk_data->num = num_clks;

Looks like variable num_clks can be removed entirely, and just do:

clk_data->num = data->num;

Thanks
-Gustavo