Skip to contentSkip to conversation

x86, mrst: Casting (void *) value returned by kmalloc is useless

PATCH In review Thomas Meyer 4 participants 4 messages Nov 18, 2011 – Nov 20, 2011 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86, mrst: Casting (void *) value returned by kmalloc is useless

The semantic patch that makes this change is available in scripts/coccinelle/api/alloc/drop_kmalloc_cast.cocci.

---

arch/x86/platform/mrst/mrst.c 2011-11-08 09:19:24.686513740 +0100 renamed from arch/x86/platform/mrst/mrst.c 2011-11-07 19:37:40.283168752 +0100 +1 -1
diff -u -p a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
@@ -331,7 +331,7 @@ static int __init sfi_parse_gpio(struct
 	num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
 	pentry = (struct sfi_gpio_table_entry *)sb->pentry;
 
-	gpio_table = (struct sfi_gpio_table_entry *)
+	gpio_table =
 				kmalloc(num * sizeof(*pentry), GFP_KERNEL);
 	if (!gpio_table)
 		return -1;
#1 lore raw
Quoted 10 lines · On Thu, 17 Nov 2011 23:43:40 +0100 Thomas Meyer <[email protected]> wrote:

The semantic patch that makes this change is available in scripts/coccinelle/api/alloc/drop_kmalloc_cast.cocci.

---

diff -u -p a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c

arch/x86/platform/mrst/mrst.c 2011-11-08 09:19:24.686513740 +0100 static int __init sfi_parse_gpio(struct · line 335

Quoted 6 lines
arch/x86/platform/mrst/mrst.c 2011-11-08 09:19:24.686513740 +0100 renamed from arch/x86/platform/mrst/mrst.c 2011-11-07 19:37:40.283168752 +0100 +1 -1
@@ -331,7 +331,7 @@ static int __init sfi_parse_gpio(struct
 	num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
 	pentry = (struct sfi_gpio_table_entry *)sb->pentry;
 
-	gpio_table = (struct sfi_gpio_table_entry *)
+	gpio_table =
 				kmalloc(num * sizeof(*pentry), GFP_KERNEL);

True but the formatting also wants fixing with that change.

#2 lore raw
Quoted 19 lines
Quoted 16 lines · On Thu, 17 Nov 2011 23:43:40 +0100 Thomas Meyer <[email protected]> wrote:

The semantic patch that makes this change is available in scripts/coccinelle/api/alloc/drop_kmalloc_cast.cocci.

---

diff -u -p a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c

arch/x86/platform/mrst/mrst.c 2011-11-08 09:19:24.686513740 +0100 renamed from arch/x86/platform/mrst/mrst.c 2011-11-07 19:37:40.283168752 +0100 +1 -1
@@ -331,7 +331,7 @@ static int __init sfi_parse_gpio(struct
       num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
       pentry = (struct sfi_gpio_table_entry *)sb->pentry;
 
-     gpio_table = (struct sfi_gpio_table_entry *)
+     gpio_table =
                               kmalloc(num * sizeof(*pentry), GFP_KERNEL);
Quoted 1 line · Alan Cox

True but the formatting also wants fixing with that change.

A conversion to kcalloc() would make sense as well.

#3 lore raw
Quoted 7 lines · Pekka Enberg
Quoted 7 lines
Quoted 7 lines

diff -u -p a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c

arch/x86/platform/mrst/mrst.c 2011-11-08 09:19:24.686513740 +0100 renamed from arch/x86/platform/mrst/mrst.c 2011-11-07 19:37:40.283168752 +0100 +0 -0
@@ -331,7 +331,7 @@ static int __init sfi_parse_gpio(struct
       num = SFI_GET_NUM_ENTRIES(sb, struct sfi_gpio_table_entry);
       pentry = (struct sfi_gpio_table_entry *)sb->pentry;
 
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
arch/x86/platform/mrst/mrst.c 2011-11-08 09:19:24.686513740 +0100 renamed from arch/x86/platform/mrst/mrst.c 2011-11-07 19:37:40.283168752 +0100 +1 -1
-     gpio_table = (struct sfi_gpio_table_entry *)
+     gpio_table =
                               kmalloc(num * sizeof(*pentry), GFP_KERNEL);
Quoted 1 line · Alan Cox

True but the formatting also wants fixing with that change.

A conversion to kcalloc() would make sense as well.

Seems unnecessary to zero the array if it's going to immediately copy the gpio table, though.