[PATCH 10/11] clk: bm1880: Assign .num before accessing .hws

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


hws[] is annotated with __counted_by(num), but bm1880_clk_probe() 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 before the loop that fills hws[].

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-bm1880.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/clk/clk-bm1880.c b/drivers/clk/clk-bm1880.c
index dc13d90bdd919..e2511991eeea2 100644
--- a/drivers/clk/clk-bm1880.c
+++ b/drivers/clk/clk-bm1880.c
@@ -893,12 +893,11 @@ static int bm1880_clk_probe(struct platform_device *pdev)
 
 	clk_data->pll_base = pll_base;
 	clk_data->sys_base = sys_base;
+	clk_data->hw_data.num = num_clks;
 
 	for (i = 0; i < num_clks; i++)
 		clk_data->hw_data.hws[i] = ERR_PTR(-ENOENT);
 
-	clk_data->hw_data.num = num_clks;
-
 	bm1880_clk_register_plls(bm1880_pll_clks,
 				 ARRAY_SIZE(bm1880_pll_clks),
 				 clk_data);

-- 
2.56.0




More information about the linux-arm-kernel mailing list