[PATCH 05/11] clk: visconti: Assign .num before accessing .hws

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


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

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/visconti/clkc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/visconti/clkc.c b/drivers/clk/visconti/clkc.c
index a75163b69751e..f8bb93d7027bc 100644
--- a/drivers/clk/visconti/clkc.c
+++ b/drivers/clk/visconti/clkc.c
@@ -195,9 +195,9 @@ struct visconti_clk_provider *visconti_init_clk(struct device *dev,
 	if (!ctx)
 		return ERR_PTR(-ENOMEM);
 
+	ctx->clk_data.num = nr_clks;
 	for (i = 0; i < nr_clks; ++i)
 		ctx->clk_data.hws[i] = ERR_PTR(-ENOENT);
-	ctx->clk_data.num = nr_clks;
 
 	ctx->dev = dev;
 	ctx->regmap = regmap;

-- 
2.56.0




More information about the linux-arm-kernel mailing list