[PATCH 06/11] clk: clocking-wizard: Assign .num before accessing .hws

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


hws[] is annotated with __counted_by(num), but
clk_wzrd_register_output_clocks() fills it before clk_wzrd_probe() sets
num. The count is still zero with Clang 20 and 21, where
devm_kzalloc_flex() does not set it, and on v6.13 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. Nodes with xlnx,static-config do not reach this code.

Set num right after the allocation.

Found by an LLM-assisted check of __counted_by users.

Fixes: bb487924b161 ("clk: clocking-wizard: use newer clk_hw API")
Cc: stable at vger.kernel.org
Signed-off-by: Ben Cressey <ben at cressey.dev>
---
 drivers/clk/xilinx/clk-xlnx-clock-wizard.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
index 9f8830b40122a..d1e9b11da2011 100644
--- a/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
+++ b/drivers/clk/xilinx/clk-xlnx-clock-wizard.c
@@ -1302,6 +1302,7 @@ static int clk_wzrd_probe(struct platform_device *pdev)
 				     nr_outputs);
 	if (!clk_wzrd)
 		return -ENOMEM;
+	clk_wzrd->clk_data.num = nr_outputs;
 	platform_set_drvdata(pdev, clk_wzrd);
 
 	clk_wzrd->base = devm_platform_ioremap_resource(pdev, 0);
@@ -1337,7 +1338,6 @@ static int clk_wzrd_probe(struct platform_device *pdev)
 		if (ret)
 			return ret;
 
-		clk_wzrd->clk_data.num = nr_outputs;
 		ret = devm_of_clk_add_hw_provider(&pdev->dev, of_clk_hw_onecell_get,
 						  &clk_wzrd->clk_data);
 		if (ret) {

-- 
2.56.0




More information about the linux-arm-kernel mailing list