summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhanzhijian <hanzhijian1991@gmail.com>2026-08-24 22:28:00 +0800
committerBrian Masney <bmasney@redhat.com>2026-09-02 10:48:59 -0400
commit712b75152c00a8ab0c56dbfe34caf88e3870ddde (patch)
tree13cfaa8eef7b77519c0600faf222f47127fd49cd
parenta1c8d531c694e193dc48ef2428877d5ea2e35134 (diff)
downloadlinux-next-712b75152c00a8ab0c56dbfe34caf88e3870ddde.tar.gz
linux-next-712b75152c00a8ab0c56dbfe34caf88e3870ddde.zip
clk: mstar: msc313-mpll: fix off-by-one in clock array allocation
The hws array of mpll->clk_data is allocated with struct_size() using ARRAY_SIZE(output_dividers) as the element count, giving it 7 elements. But the probe function stores the MPLL clock at hws[0] and one fixed-factor clock for each output divider at hws[i + 1] for i in [0, ARRAY_SIZE(output_dividers)), writing 8 elements in total. The final write to hws[7] is past the end of the allocation. clk_data->num is also set to NUMOUTPUTS (8), so the clock framework reads hws[0..7], again accessing hws[7] out of bounds. Use NUMOUTPUTS as the element count so the allocation matches the number of clocks actually stored and exposed. Found by smatch: drivers/clk/mstar/clk-msc313-mpll.c:134 msc313_mpll_probe() error: buffer overflow 'mpll->clk_data->hws' 7 <= 7 Fixes: bef7a78da716 ("clk: mstar: MStar/SigmaStar MPLL driver") Cc: stable@vger.kernel.org Signed-off-by: hanzhijian <hanzhijian1991@gmail.com> Reviewed-by: Brian Masney <bmasney@redhat.com> Signed-off-by: Brian Masney <bmasney@redhat.com>
-rw-r--r--drivers/clk/mstar/clk-msc313-mpll.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/clk/mstar/clk-msc313-mpll.c b/drivers/clk/mstar/clk-msc313-mpll.c
index 61beb4e87525..bd45aa0aec01 100644
--- a/drivers/clk/mstar/clk-msc313-mpll.c
+++ b/drivers/clk/mstar/clk-msc313-mpll.c
@@ -105,7 +105,7 @@ static int msc313_mpll_probe(struct platform_device *pdev)
return PTR_ERR(mpll->loop_div_second);
mpll->clk_data = devm_kzalloc(dev, struct_size(mpll->clk_data, hws,
- ARRAY_SIZE(output_dividers)), GFP_KERNEL);
+ NUMOUTPUTS), GFP_KERNEL);
if (!mpll->clk_data)
return -ENOMEM;