Skip to content

Commit 2f7ae8a

Browse files
committed
clk: microchip: mpfs-ccc: fix out of bounds access during output registration
UBSAN reported an out of bounds access during registration of the last two outputs. This out of bounds access occurs because space is only allocated in the hws array for two PLLs and the four output dividers that each has, but the defined IDs contain two DLLS and their two outputs each, which are not supported by the driver. The ID order is PLLs -> DLLs -> PLL outputs -> DLL outputs. Decrement the PLL output IDs by two while adding them to the array to avoid the problem. Fixes: d39fb17 ("clk: microchip: add PolarFire SoC fabric clock support") CC: stable@vger.kernel.org Reviewed-by: Brian Masney <bmasney@redhat.com> Signed-off-by: Conor Dooley <conor.dooley@microchip.com>
1 parent 6de23f8 commit 2f7ae8a

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

drivers/clk/microchip/clk-mpfs-ccc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static int mpfs_ccc_register_outputs(struct device *dev, struct mpfs_ccc_out_hw_
178178
return dev_err_probe(dev, ret, "failed to register clock id: %d\n",
179179
out_hw->id);
180180

181-
data->hw_data.hws[out_hw->id] = &out_hw->divider.hw;
181+
data->hw_data.hws[out_hw->id - 2] = &out_hw->divider.hw;
182182
}
183183

184184
return 0;
@@ -234,6 +234,10 @@ static int mpfs_ccc_probe(struct platform_device *pdev)
234234
unsigned int num_clks;
235235
int ret;
236236

237+
/*
238+
* If DLLs get added here, mpfs_ccc_register_outputs() currently packs
239+
* sparse clock IDs in the hws array
240+
*/
237241
num_clks = ARRAY_SIZE(mpfs_ccc_pll_clks) + ARRAY_SIZE(mpfs_ccc_pll0out_clks) +
238242
ARRAY_SIZE(mpfs_ccc_pll1out_clks);
239243

0 commit comments

Comments
 (0)