Skip to contentSkip to conversation

clk: sifive: allocate sufficient memory for struct __prci_data

PATCH In review Vincent Chen 3 participants 5 messages Jun 23, 2020 – Jun 29, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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")
---
 drivers/clk/sifive/fu540-prci.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/clk/sifive/fu540-prci.c +4 -1
index 6282ee2f361c..a8901f90a61a 100644
@@ -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;
 
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 19 lines · On Mon, 22 Jun 2020 18:24:17 PDT (-0700), [email protected] wrote:

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")
---
 drivers/clk/sifive/fu540-prci.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/clk/sifive/fu540-prci.c +0 -0
index 6282ee2f361c..a8901f90a61a 100644

drivers/clk/sifive/fu540-prci.c static int sifive_fu540_prci_probe(struct platform_device *pdev) · line 594

Quoted 10 lines
drivers/clk/sifive/fu540-prci.c +4 -1
@@ -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;

This is on fixes, thanks!

maintainer
#2 lore raw

Quoting Palmer Dabbelt (2020-06-25 15:13:39)

Quoted 23 lines · On Mon, 22 Jun 2020 18:24:17 PDT (-0700), [email protected] wrote:
Quoted 22 lines

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")
---
 drivers/clk/sifive/fu540-prci.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/clk/sifive/fu540-prci.c +0 -0
index 6282ee2f361c..a8901f90a61a 100644
@@ -586,7 +586,10 @@ static int sifive_fu540_prci_probe(struct platform_device *pdev)
      struct __prci_data *pd;
      int r;
 
Quoted 9 lines

drivers/clk/sifive/fu540-prci.c static int sifive_fu540_prci_probe(struct platform_device *pdev) · line 594

Quoted 7 lines
drivers/clk/sifive/fu540-prci.c +4 -1
-     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;

This is on fixes, thanks!

Does that mean applied to sifive tree? I see it in next but only noticed this by chance because it wasn't sent to the linux-clk mailing list.

maintainer
#3 lore raw
Quoted 34 lines · On Mon, 29 Jun 2020 16:23:47 PDT (-0700), [email protected] wrote:

Quoting Palmer Dabbelt (2020-06-25 15:13:39)

Quoted 23 lines · On Mon, 22 Jun 2020 18:24:17 PDT (-0700), [email protected] wrote:
Quoted 22 lines

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")
---
 drivers/clk/sifive/fu540-prci.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/clk/sifive/fu540-prci.c +0 -0
index 6282ee2f361c..a8901f90a61a 100644
@@ -586,7 +586,10 @@ static int sifive_fu540_prci_probe(struct platform_device *pdev)
      struct __prci_data *pd;
      int r;
 
Quoted 9 lines

drivers/clk/sifive/fu540-prci.c static int sifive_fu540_prci_probe(struct platform_device *pdev) · line 594

Quoted 7 lines
drivers/clk/sifive/fu540-prci.c +4 -1
-     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;

This is on fixes, thanks!

Quoted 2 lines

Does that mean applied to sifive tree? I see it in next but only noticed this by chance because it wasn't sent to the linux-clk mailing list.

Sorry, I was going a bit too fast and didn't realize this wasn't in arch/riscv/ so I didn't wait for an ack. I put it on my fixes branch, which is what I sent for the RCs. That's merged into linux-next as well, as far as I understand that's the normal way to do things. It ended up in Linus' tree as d0a5fdf4cc83 ("clk: sifive: allocate sufficient memory for struct __prci_data"), which is in rc3.

We don't really have a SiFive tree, the SiFive stuff just goes in through the RISC-V tree. In theory I've been meaning to split them up for a while, but given the maintainers are the same I just never got around to doing so.

LMK if I screwed something up.

maintainer
#4 lore raw

Quoting Palmer Dabbelt (2020-06-29 16:34:10)

Quoted 12 lines · On Mon, 29 Jun 2020 16:23:47 PDT (-0700), [email protected] wrote:
Quoted 3 lines

Does that mean applied to sifive tree? I see it in next but only noticed this by chance because it wasn't sent to the linux-clk mailing list.

Sorry, I was going a bit too fast and didn't realize this wasn't in arch/riscv/ so I didn't wait for an ack. I put it on my fixes branch, which is what I sent for the RCs. That's merged into linux-next as well, as far as I understand that's the normal way to do things. It ended up in Linus' tree as d0a5fdf4cc83 ("clk: sifive: allocate sufficient memory for struct __prci_data"), which is in rc3.

Quoted 5 lines

We don't really have a SiFive tree, the SiFive stuff just goes in through the RISC-V tree. In theory I've been meaning to split them up for a while, but given the maintainers are the same I just never got around to doing so.

LMK if I screwed something up.

No worries. I would have noticed this patch earlier if it had been sent to the linux-clk mailing list which I use to catch patches that should be reviewed for the clk tree. I'm not overly concerned. Thanks.