[PATCH 03/11] clk: mmp: audio: Assign .num before accessing .hws
Ben Cressey
ben at cressey.dev
Thu Dec 3 16:15:41 PST 2026
hws[] is annotated with __counted_by(num), but register_clocks() 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/mmp/clk-audio.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/clk/mmp/clk-audio.c b/drivers/clk/mmp/clk-audio.c
index 19233684fbf9b..6b74aaed64b41 100644
--- a/drivers/clk/mmp/clk-audio.c
+++ b/drivers/clk/mmp/clk-audio.c
@@ -340,7 +340,6 @@ static int register_clocks(struct mmp2_audio_clk *priv, struct device *dev)
priv->clk_data.hws[MMP2_CLK_AUDIO_SYSCLK] = &priv->sysclk_gate.hw;
priv->clk_data.hws[MMP2_CLK_AUDIO_SSPA0] = &priv->sspa0_gate.hw;
priv->clk_data.hws[MMP2_CLK_AUDIO_SSPA1] = &priv->sspa1_gate.hw;
- priv->clk_data.num = CLK_AUDIO_NR_CLKS;
return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
&priv->clk_data);
@@ -356,6 +355,7 @@ static int mmp2_audio_clk_probe(struct platform_device *pdev)
if (!priv)
return -ENOMEM;
+ priv->clk_data.num = CLK_AUDIO_NR_CLKS;
spin_lock_init(&priv->lock);
platform_set_drvdata(pdev, priv);
--
2.56.0
More information about the linux-arm-kernel
mailing list