Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752279AbdGIM0T (ORCPT ); Sun, 9 Jul 2017 08:26:19 -0400 Received: from mail-it0-f68.google.com ([209.85.214.68]:32818 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752218AbdGIM0R (ORCPT ); Sun, 9 Jul 2017 08:26:17 -0400 MIME-Version: 1.0 In-Reply-To: <20170708110157.jkpg6foz35lckdqu@ihha.localdomain> References: <20170707144521.4520-1-gehariprasath@gmail.com> <20170708110157.jkpg6foz35lckdqu@ihha.localdomain> From: hari prasath Date: Sun, 9 Jul 2017 17:56:15 +0530 Message-ID: Subject: Re: [PATCH v2] staging: atomisp: use kstrdup to replace kmalloc and memcpy To: Sakari Ailus Cc: mchehab@kernel.org, "gregkh@linuxfoundation.org" , Alan Cox , rvarsha016@gmail.com, Julia Lawall , SIMRAN SINGHAL , linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1996 Lines: 60 On 8 July 2017 at 16:31, Sakari Ailus wrote: > Hi Hari, > > On Fri, Jul 07, 2017 at 08:15:21PM +0530, Hari Prasath wrote: >> kstrdup kernel primitive can be used to replace kmalloc followed by >> string copy. This was reported by coccinelle tool >> >> Signed-off-by: Hari Prasath >> --- >> .../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; > > The patch also changes the return value in error cases. I believe the > caller(s) expect to get errors in the IA_CCS_ERR_* range. Hi, In this particular case, the calling function just checks if it's not success defined by a enum. I think returning -ENOMEM would not effect, at least in this case. - Hari Prasath > >> bd->name = fw_minibuffer[index].name = namebuffer; >> } else { >> bd->name = name; > > -- > Regards, > > Sakari Ailus > e-mail: sakari.ailus@iki.fi XMPP: sailus@retiisi.org.uk -- Regards, G.E.Hari Prasath