clk: sifive: allocate sufficient memory for struct __prci_data
authorVincent Chen <vincent.chen@sifive.com>
Tue, 23 Jun 2020 01:24:17 +0000 (09:24 +0800)
committerPalmer Dabbelt <palmerdabbelt@google.com>
Thu, 25 Jun 2020 22:04:13 +0000 (15:04 -0700)
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>
drivers/clk/sifive/fu540-prci.c

index 6282ee2f361cda507f69fe9a9b1eca75e27ad3ee..a8901f90a61ac08f6dba531cbc8f3760deff39f2 100644 (file)
@@ -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;