Skip to contentSkip to conversation

staging: rdma: hfi1: Replace kmalloc and memcpy with kmemdup

PATCH In review Amitoj Kaur Chawla 2 participants 3 messages Feb 15, 2016 – Feb 17, 2016 Staging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: rdma: hfi1: Replace kmalloc and memcpy with kmemdup

Replace kmalloc and memcpy with kmemdup. Found using Coccinelle.

The semantic patch used to make this change can be found here:
scripts/coccinelle/api/memdup.cocci

---
 drivers/staging/rdma/hfi1/efivar.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/rdma/hfi1/efivar.c +1 -2
index e569f9f..47dfe25 100644
@@ -127,13 +127,12 @@ static int read_efi_var(const char *name, unsigned long *size,
 	 * temporary buffer.  Now allocate a correctly sized
 	 * buffer.
 	 */
-	data = kmalloc(temp_size, GFP_KERNEL);
+	data = kmemdup(temp_buffer, temp_size, GFP_KERNEL);
 	if (!data) {
 		ret = -ENOMEM;
 		goto fail;
 	}
 
-	memcpy(data, temp_buffer, temp_size);
 	*size = temp_size;
 	*return_data = data;
 
Signature · 1 line
1.9.1
#1 lore raw
Quoted 4 lines · Amitoj Kaur Chawla

Replace kmalloc and memcpy with kmemdup. Found using Coccinelle.

The semantic patch used to make this change can be found here:
scripts/coccinelle/api/memdup.cocci

No need to change, but in this situation you can also put:

Generated-by: scripts/coccinelle/api/memdup.cocci

Quoted 34 lines
---
 drivers/staging/rdma/hfi1/efivar.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/staging/rdma/hfi1/efivar.c +1 -3
index e569f9f..47dfe25 100644
@@ -127,13 +127,12 @@ static int read_efi_var(const char *name, unsigned long *size,
 	 * temporary buffer.  Now allocate a correctly sized
 	 * buffer.
 	 */
-	data = kmalloc(temp_size, GFP_KERNEL);
+	data = kmemdup(temp_buffer, temp_size, GFP_KERNEL);
 	if (!data) {
 		ret = -ENOMEM;
 		goto fail;
 	}
 
-	memcpy(data, temp_buffer, temp_size);
 	*size = temp_size;
 	*return_data = data;
 
--

1.9.1

--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20160215192524.GA30333%40amitoj-Inspiron-3542.
For more options, visit https://groups.google.com/d/optout.

#2 lore raw
Quoted 4 lines · Julia Lawall

No need to change, but in this situation you can also put:

Generated-by: scripts/coccinelle/api/memdup.cocci

Oh okay will take care in the future.

Thanks,
Amitoj