mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFT PATCH v2] Use kmalloc_array() instead of kmalloc()
@ 2025-11-23  7:09 Sidharth Seela
  2026-01-10 16:17 ` Claudiu Beznea
  0 siblings, 1 reply; 2+ messages in thread
From: Sidharth Seela @ 2025-11-23  7:09 UTC (permalink / raw)
  To: claudiu.beznea, alexandre.belloni, nicolas.ferre, sboyd, mturquette
  Cc: linux-clk, linux-arm-kernel, linux-kernel, david.hunter.linux,
	skhan, khalid, Sidharth Seela

Refactor to new API, for cases with dynamic size calculations
inside kmalloc(). Such calculations were found using grep in the
sources. The patch compiles properly with multi_v7_defconfig
and multi_v5_defconfig and generates object files for the following
driver files.

Signed-off-by: Sidharth Seela <sidharthseela@gmail.com>
---
Changelog:
v1:https://lore.kernel.org/all/20250924145552.55058-1-sidharthseela@gmail.com/
-refactor code and run checkpatch.
-use sizeof(*ptr) not sizeof(void*).
-add RFT and the how the issue was found.

diff --git a/drivers/clk/at91/sam9x7.c b/drivers/clk/at91/sam9x7.c
index 89868a0aeaba..01bf557034e0 100644
--- a/drivers/clk/at91/sam9x7.c
+++ b/drivers/clk/at91/sam9x7.c
@@ -754,9 +754,9 @@ static void __init sam9x7_pmc_setup(struct device_node *np)
 	if (!sam9x7_pmc)
 		return;
 
-	clk_mux_buffer = kmalloc(sizeof(void *) *
-				 (ARRAY_SIZE(sam9x7_gck)),
-				 GFP_KERNEL);
+	clk_mux_buffer = kmalloc_array(ARRAY_SIZE(sam9x7_gck),
+				       sizeof(*clk_mux_buffer),
+				       GFP_KERNEL);
 	if (!clk_mux_buffer)
 		goto err_free;
 
diff --git a/drivers/clk/at91/sama7d65.c b/drivers/clk/at91/sama7d65.c
index 7dee2b160ffb..91a5615f724a 100644
--- a/drivers/clk/at91/sama7d65.c
+++ b/drivers/clk/at91/sama7d65.c
@@ -1127,9 +1127,9 @@ static void __init sama7d65_pmc_setup(struct device_node *np)
 	if (!sama7d65_pmc)
 		return;
 
-	alloc_mem = kmalloc(sizeof(void *) *
-			    (ARRAY_SIZE(sama7d65_mckx) + ARRAY_SIZE(sama7d65_gck)),
-			    GFP_KERNEL);
+	alloc_mem = kmalloc_array(ARRAY_SIZE(sama7d65_mckx) + ARRAY_SIZE(sama7d65_gck),
+				  sizeof(*alloc_mem),
+				  GFP_KERNEL);
 	if (!alloc_mem)
 		goto err_free;
 
diff --git a/drivers/clk/at91/sama7g5.c b/drivers/clk/at91/sama7g5.c
index 1340c2b00619..a12381f6c068 100644
--- a/drivers/clk/at91/sama7g5.c
+++ b/drivers/clk/at91/sama7g5.c
@@ -1004,9 +1004,9 @@ static void __init sama7g5_pmc_setup(struct device_node *np)
 	if (!sama7g5_pmc)
 		return;
 
-	alloc_mem = kmalloc(sizeof(void *) *
-			    (ARRAY_SIZE(sama7g5_mckx) + ARRAY_SIZE(sama7g5_gck)),
-			    GFP_KERNEL);
+	alloc_mem = kmalloc_array(ARRAY_SIZE(sama7g5_mckx) + ARRAY_SIZE(sama7g5_gck),
+				  sizeof(*alloc_mem),
+				  GFP_KERNEL);
 	if (!alloc_mem)
 		goto err_free;
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [RFT PATCH v2] Use kmalloc_array() instead of kmalloc()
  2025-11-23  7:09 [RFT PATCH v2] Use kmalloc_array() instead of kmalloc() Sidharth Seela
@ 2026-01-10 16:17 ` Claudiu Beznea
  0 siblings, 0 replies; 2+ messages in thread
From: Claudiu Beznea @ 2026-01-10 16:17 UTC (permalink / raw)
  To: Sidharth Seela, alexandre.belloni, nicolas.ferre, sboyd, mturquette
  Cc: linux-clk, linux-arm-kernel, linux-kernel, david.hunter.linux,
	skhan, khalid

Please use "clk: at91: Use kmalloc_array() instead of kmalloc()" in 
patch title.

On 11/23/25 09:09, Sidharth Seela wrote:
> Refactor to new API, for cases with dynamic size calculations
> inside kmalloc(). Such calculations were found using grep in the
> sources. The patch compiles properly with multi_v7_defconfig
> and multi_v5_defconfig and generates object files for the following
> driver files.

Patch description should answer to "what?" are you doing and "why?" are 
you doing it. Please specify also why are you doing this change.

The rest looks good to me.

I tested it and saw no issues.

Thank you,
Claudiu

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-01-10 16:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-23  7:09 [RFT PATCH v2] Use kmalloc_array() instead of kmalloc() Sidharth Seela
2026-01-10 16:17 ` Claudiu Beznea

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®