linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] staging: atomisp: replace kmalloc & memcpy with kmemdup
@ 2017-07-07 11:50 Hari Prasath
  2017-07-07 11:55 ` Alan Cox
  0 siblings, 1 reply; 3+ messages in thread
From: Hari Prasath @ 2017-07-07 11:50 UTC (permalink / raw)
  To: mchehab
  Cc: gregkh, alan, rvarsha016, julia.lawall, singhalsimran0,
	linux-media, devel, linux-kernel

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

Signed-off-by: Hari Prasath <gehariprasath@gmail.com>
---
 drivers/staging/media/atomisp/pci/atomisp2/css2400/sh_css_firmware.c | 4 +---
 1 file changed, 1 insertion(+), 3 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..58d4619 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
@@ -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;
-- 
2.10.0.GIT

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: atomisp: replace kmalloc & memcpy with kmemdup
  2017-07-07 11:50 [PATCH] staging: atomisp: replace kmalloc & memcpy with kmemdup Hari Prasath
@ 2017-07-07 11:55 ` Alan Cox
  2017-07-07 13:22   ` hari prasath
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Cox @ 2017-07-07 11:55 UTC (permalink / raw)
  To: Hari Prasath, mchehab
  Cc: gregkh, rvarsha016, julia.lawall, singhalsimran0, linux-media,
	devel, linux-kernel

On Fri, 2017-07-07 at 17:20 +0530, Hari Prasath wrote:
> 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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: atomisp: replace kmalloc & memcpy with kmemdup
  2017-07-07 11:55 ` Alan Cox
@ 2017-07-07 13:22   ` hari prasath
  0 siblings, 0 replies; 3+ messages in thread
From: hari prasath @ 2017-07-07 13:22 UTC (permalink / raw)
  To: Alan Cox
  Cc: linux-media, Julia Lawall, mchehab, linux-kernel, SIMRAN SINGHAL,
	rvarsha016, devel, gregkh

On 07-Jul-2017 5:25 PM, "Alan Cox" <alan@linux.intel.com> wrote:

On Fri, 2017-07-07 at 17:20 +0530, Hari Prasath wrote:
> 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 ?
> Yes & thanks for pointing me that. I will send a v2 version.

-Hari

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-07-07 13:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-07 11:50 [PATCH] staging: atomisp: replace kmalloc & memcpy with kmemdup Hari Prasath
2017-07-07 11:55 ` Alan Cox
2017-07-07 13:22   ` hari prasath

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).