[PATCH v2] staging: atomisp: use kstrdup to replace kmalloc and memcpy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 .../media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c       | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c b/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c
index 34cc56f..68db87b 100644
--- a/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c
+++ b/drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c
@@ -144,14 +144,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);
-		if (namebuffer == NULL)
-			return IA_CSS_ERR_CANNOT_ALLOCATE_MEMORY;
-
-		memcpy(namebuffer, name, namelength + 1);
 
+		namebuffer = kstrdup(name, GFP_KERNEL);
+		if (!namebuffer)
+			return -ENOMEM;
 		bd->name = fw_minibuffer[index].name = namebuffer;
 	} else {
 		bd->name = name;
-- 
2.10.0.GIT

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel



[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux