media: staging: atomisp: use kstrdup to replace kmalloc and memcpy
authorHari Prasath <gehariprasath@gmail.com>
Mon, 10 Jul 2017 06:17:00 +0000 (02:17 -0400)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Wed, 19 Jul 2017 20:25:28 +0000 (16:25 -0400)
kstrdup kernel primitive can be used to replace kmalloc followed by
string copy. This was reported by coccinelle tool.

Signed-off-by: Hari Prasath <gehariprasath@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c

index eecd8cf7195161c2caf99a6f6f2cae26801c4759..63582161050a33e239fe11163f60262c8d29963e 100644 (file)
@@ -131,14 +131,10 @@ sh_css_load_blob_info(const char *fw, const struct ia_css_fw_info *bi, struct ia
 
        if (bi->type == ia_css_isp_firmware || bi->type == ia_css_sp_firmware) {
                char *namebuffer;
-               int namelength = (int)strlen(name);
 
-               namebuffer = (char *) kmalloc(namelength + 1, GFP_KERNEL);
-               if (namebuffer == NULL)
+               namebuffer = kstrdup(name, GFP_KERNEL);
+               if (!namebuffer)
                        return IA_CSS_ERR_CANNOT_ALLOCATE_MEMORY;
-
-               memcpy(namebuffer, name, namelength + 1);
-
                bd->name = fw_minibuffer[index].name = namebuffer;
        } else {
                bd->name = name;