Skip to contentSkip to conversation

staging: atomisp: replace kmalloc & memcpy with kmemdup

PATCH In review Hari Prasath 2 participants 3 messages Jul 7, 2017

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 staging: atomisp: replace kmalloc & memcpy with kmemdup

kmemdup can be used to replace kmalloc followed by a memcpy.This was pointed out by the coccinelle tool.

---
 drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c +1 -3
index 34cc56f..58d4619 100644
@@ -146,12 +146,10 @@ sh_css_load_blob_info(const char *fw, const struct ia_css_fw_info *bi, struct ia
 		char *namebuffer;
 		int namelength = (int)strlen(name);
 
-		namebuffer = (char *) kmalloc(namelength + 1, GFP_KERNEL);
+		namebuffer = (char *)kmemdup(name, namelength + 1, GFP_KERNEL);
 		if (namebuffer == NULL)
 			return IA_CSS_ERR_CANNOT_ALLOCATE_MEMORY;
 
-		memcpy(namebuffer, name, namelength + 1);
-
 		bd->name = fw_minibuffer[index].name = namebuffer;
 	} else {
 		bd->name = name;
Signature · 1 line
2.10.0.GIT
#1 lore raw
Quoted 2 lines · Hari Prasath

kmemdup can be used to replace kmalloc followed by a memcpy.This was pointed out by the coccinelle tool.

And kstrdup could do the job even better I think ?

Alan

#2 lore raw

On 07-Jul-2017 5:25 PM, "Alan Cox" <[email protected]> wrote:

Quoted 2 lines · Hari Prasath

kmemdup can be used to replace kmalloc followed by a memcpy.This was pointed out by the coccinelle tool.

And kstrdup could do the job even better I think ?

Quoted 1 line

Yes & thanks for pointing me that. I will send a v2 version.

-Hari