Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0935afc3 authored by Vincent Chen's avatar Vincent Chen Committed by Sasha Levin
Browse files

clk: sifive: allocate sufficient memory for struct __prci_data



[ Upstream commit d0a5fdf4cc83dabcdea668f971b8a2e916437711 ]

The (struct __prci_data).hw_clks.hws is an array with dynamic elements.
Using struct_size(pd, hw_clks.hws, ARRAY_SIZE(__prci_init_clocks))
instead of sizeof(*pd) to get the correct memory size of
struct __prci_data for sifive/fu540-prci. After applying this
modifications, the kernel runs smoothly with CONFIG_SLAB_FREELIST_RANDOM
enabled on the HiFive unleashed board.

Fixes: 30b8e27e ("clk: sifive: add a driver for the SiFive FU540 PRCI IP block")
Signed-off-by: default avatarVincent Chen <vincent.chen@sifive.com>
Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent b78bae5a
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -586,7 +586,10 @@ static int sifive_fu540_prci_probe(struct platform_device *pdev)
	struct __prci_data *pd;
	int r;

	pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL);
	pd = devm_kzalloc(dev,
			  struct_size(pd, hw_clks.hws,
				      ARRAY_SIZE(__prci_init_clocks)),
			  GFP_KERNEL);
	if (!pd)
		return -ENOMEM;