Skip to contentSkip to conversation

clk: at91: sam9x7: Use kmalloc_array() instead of kmalloc()

PATCH RESEND Superseded Sidharth Seela 3 participants 4 messages Sep 24, 2025 – Nov 8, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 clk: at91: sam9x7: Use kmalloc_array() instead of kmalloc()

Replace kmalloc with kmalloc array in clk/at91/sam9x7.c. Refactor to new API, for cases with dynamic size calculations inside kmalloc().

Resend is to correct previously sent patches mailing address.

---

drivers/clk/at91/sam9x7.c +3 -3
index ffab32b047a0..0c0a746a183d 100644
@@ -748,9 +748,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(void *),
+					GFP_KERNEL);
 	if (!clk_mux_buffer)
 		goto err_free;
 
Signature · 1 line
2.39.5 (Apple Git-154)
#1 lore raw
Quoted 3 lines · Sidharth Seela

Replace kmalloc with kmalloc array in clk/at91/sam9x7.c. Refactor to new API, for cases with dynamic size calculations inside kmalloc().

This following line doesn't belong in commit log.

Can you add details on how you tested this patch and also how you found the problem to begin with.

Quoted 13 lines

Resend is to correct previously sent patches mailing address.

---

drivers/clk/at91/sam9x7.c +0 -0
index ffab32b047a0..0c0a746a183d 100644
@@ -748,9 +748,9 @@ static void __init sam9x7_pmc_setup(struct device_node *np)
  	if (!sam9x7_pmc)
  		return;

drivers/clk/at91/sam9x7.c static void __init sam9x7_pmc_setup(struct device_node *np) · line 756

Quoted 10 lines
drivers/clk/at91/sam9x7.c +3 -3
 
-	clk_mux_buffer = kmalloc(sizeof(void *) *
-				 (ARRAY_SIZE(sam9x7_gck)),
-				 GFP_KERNEL);
+	clk_mux_buffer = kmalloc_array(ARRAY_SIZE(sam9x7_gck),
+					sizeof(void *),
+					GFP_KERNEL);
  	if (!clk_mux_buffer)
  		goto err_free;
 

thanks,
-- Shuah

#2 lore raw
Quoted 1 line · Shuah Khan

This following line doesn't belong in commit log.

This was one of my early patches. It won't happen again.

Quoted 2 lines

Can you add details on how you tested this patch and also how you found the problem to begin with.

I used grep to find instances of kmalloc and went through the ones with size calculations inside them.
I did compile testing, My mistake, I forgot to add request for test. I would like to retract this patch for the same.

Signature · 3 lines
Thanks,
Sidharth Seela
www.realtimedesign.org
maintainer
#3 lore raw
In reply to Sidharth Seela

Hi, Sidharth,

Quoted 12 lines · Sidharth Seela

Replace kmalloc with kmalloc array in clk/at91/sam9x7.c. Refactor to new API, for cases with dynamic size calculations inside kmalloc().

Resend is to correct previously sent patches mailing address.

---

drivers/clk/at91/sam9x7.c +0 -0
index ffab32b047a0..0c0a746a183d 100644

drivers/clk/at91/sam9x7.c static void __init sam9x7_pmc_setup(struct device_node *np) · line 752

Quoted 8 lines
drivers/clk/at91/sam9x7.c +2 -3
@@ -748,9 +748,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(void *),

sizeof(*clk_mux_buffer)

Also, this line should be aligned on the above "(". Please run checkpatch.pl.

Could you please update the other at91 clock drivers?

[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst

drivers/clk/at91/sam9x7.c static void __init sam9x7_pmc_setup(struct device_node *np) · line 753

Quoted 1 line
drivers/clk/at91/sam9x7.c +1 -0
+					GFP_KERNEL);

This like could fit on the above one.

Thank you,
Claudiu

Quoted 3 lines
drivers/clk/at91/sam9x7.c +0 -0
 	if (!clk_mux_buffer)
 		goto err_free;