[PATCH 02/11] clk: lmk04832: Assign .num before accessing .hws

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


hws[] is annotated with __counted_by(num), but
lmk04832_register_clkout() fills it before lmk04832_probe() 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/clk-lmk04832.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk-lmk04832.c b/drivers/clk/clk-lmk04832.c
index e6e771e8eb145..ad66cf097b9ba 100644
--- a/drivers/clk/clk-lmk04832.c
+++ b/drivers/clk/clk-lmk04832.c
@@ -1435,6 +1435,8 @@ static int lmk04832_probe(struct spi_device *spi)
 		return ret;
 	}
 
+	lmk->clk_data->num = info->num_channels;
+
 	device_property_read_u32(lmk->dev, "ti,vco-hz", &lmk->vco_rate);
 
 	lmk->sysref_ddly = 8;
@@ -1530,7 +1532,6 @@ static int lmk04832_probe(struct spi_device *spi)
 		}
 	}
 
-	lmk->clk_data->num = info->num_channels;
 	ret = devm_of_clk_add_hw_provider(lmk->dev, of_clk_hw_onecell_get,
 					  lmk->clk_data);
 	if (ret) {

-- 
2.56.0




More information about the linux-arm-kernel mailing list