[PATCH 07/11] clk: clps711x: Assign .num before accessing .hws

Ben Cressey ben at cressey.dev
Thu Dec 3 16:15:45 PST 2026


hws[] is annotated with __counted_by(num), but clps711x_clk_init_dt()
fills it before it sets num. The count is still zero with Clang 20 and
21, where kzalloc_flex() does not set it, and on v6.6 to v6.19, which
use kzalloc(). With __counted_by enabled, CONFIG_UBSAN_BOUNDS reports
the accesses and CONFIG_UBSAN_TRAP makes the first one trap during boot.

Set num right after the allocation.

Found by an LLM-assisted check of __counted_by users.

Fixes: f316cdff8d67 ("clk: Annotate struct clk_hw_onecell_data with __counted_by")
Cc: stable at vger.kernel.org
Signed-off-by: Ben Cressey <ben at cressey.dev>
---
 drivers/clk/clk-clps711x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/clk-clps711x.c b/drivers/clk/clk-clps711x.c
index 27a57a9b3cb34..e2185b3daac99 100644
--- a/drivers/clk/clk-clps711x.c
+++ b/drivers/clk/clk-clps711x.c
@@ -57,6 +57,7 @@ static void __init clps711x_clk_init_dt(struct device_node *np)
 				    CLPS711X_CLK_MAX);
 	BUG_ON(!clps711x_clk);
 
+	clps711x_clk->clk_data.num = CLPS711X_CLK_MAX;
 	spin_lock_init(&clps711x_clk->lock);
 
 	/* Read PLL multiplier value and sanity check */
@@ -139,7 +140,6 @@ static void __init clps711x_clk_init_dt(struct device_node *np)
 			pr_err("clk %i: register failed with %ld\n",
 			       tmp, PTR_ERR(clps711x_clk->clk_data.hws[tmp]));
 
-	clps711x_clk->clk_data.num = CLPS711X_CLK_MAX;
 	of_clk_add_hw_provider(np, of_clk_hw_onecell_get,
 			       &clps711x_clk->clk_data);
 }

-- 
2.56.0




More information about the linux-arm-kernel mailing list