Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: sifive: allocate sufficient memory for struct __prci_data

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: 30b8e27e3b58 ("clk: sifive: add a driver for the SiFive FU540 PRCI IP block")
Signed-off-by: Vincent Chen <vincent.chen@sifive.com>
Signed-off-by: Palmer Dabbelt <palmerdabbelt@google.com>

authored by

Vincent Chen and committed by
Palmer Dabbelt
d0a5fdf4 a0fc3b32

+4 -1
+4 -1
drivers/clk/sifive/fu540-prci.c
··· 586 586 struct __prci_data *pd; 587 587 int r; 588 588 589 - pd = devm_kzalloc(dev, sizeof(*pd), GFP_KERNEL); 589 + pd = devm_kzalloc(dev, 590 + struct_size(pd, hw_clks.hws, 591 + ARRAY_SIZE(__prci_init_clocks)), 592 + GFP_KERNEL); 590 593 if (!pd) 591 594 return -ENOMEM; 592 595