Skip to contentSkip to conversation

MIPS: Alchemy: Switch to use kmemdup_array()

PATCH Applied Andy Shevchenko 2 participants 2 messages Jun 6, 2024 – Jun 11, 2024 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: Alchemy: Switch to use kmemdup_array()

Let the kememdup_array() take care about multiplication and possible overflows.

---
 arch/mips/alchemy/common/platform.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/mips/alchemy/common/platform.c +4 -4
index d4ab34b3b404..da74cae6b43a 100644
@@ -409,8 +409,8 @@ static void __init alchemy_setup_macs(int ctype)
 	if (alchemy_get_macs(ctype) < 1)
 		return;
 
-	macres = kmemdup(au1xxx_eth0_resources[ctype],
-			 sizeof(struct resource) * MAC_RES_COUNT, GFP_KERNEL);
+	macres = kmemdup_array(au1xxx_eth0_resources[ctype], MAC_RES_COUNT,
+			       sizeof(*macres), GFP_KERNEL);
 	if (!macres) {
 		printk(KERN_INFO "Alchemy: no memory for MAC0 resources\n");
 		return;
@@ -430,8 +430,8 @@ static void __init alchemy_setup_macs(int ctype)
 	if (alchemy_get_macs(ctype) < 2)
 		return;
 
-	macres = kmemdup(au1xxx_eth1_resources[ctype],
-			 sizeof(struct resource) * MAC_RES_COUNT, GFP_KERNEL);
+	macres = kmemdup_array(au1xxx_eth1_resources[ctype], MAC_RES_COUNT,
+			       sizeof(*macres), GFP_KERNEL);
 	if (!macres) {
 		printk(KERN_INFO "Alchemy: no memory for MAC1 resources\n");
 		return;
Signature · 1 line
2.43.0.rc1.1336.g36b5255a03ac
maintainer Applied
#1 lore raw
Quoted 7 lines · Andy Shevchenko

Let the kememdup_array() take care about multiplication and possible overflows.

---
 arch/mips/alchemy/common/platform.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

applied to mips-next.

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]