Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1683581
| From | Sakari Ailus <sakari.ailus@iki.fi> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | Re: [PATCH v2] staging: atomisp: use kstrdup to replace kmalloc and memcpy |
| Date | 2017-07-08 13:10 +0200 |
| Message-ID | <u0VMB-1ql-7@gated-at.bofh.it> (permalink) |
| References | <u0CJY-5m6-5@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
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 <gehariprasath@gmail.com>
> ---
> .../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.
> 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
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v2] staging: atomisp: use kstrdup to replace kmalloc and memcpy Hari Prasath <gehariprasath@gmail.com> - 2017-07-07 16:50 +0200
Re: [PATCH v2] staging: atomisp: use kstrdup to replace kmalloc and memcpy Sakari Ailus <sakari.ailus@iki.fi> - 2017-07-08 13:10 +0200
Re: [PATCH v2] staging: atomisp: use kstrdup to replace kmalloc and memcpy hari prasath <gehariprasath@gmail.com> - 2017-07-09 14:30 +0200
Re: [PATCH v2] staging: atomisp: use kstrdup to replace kmalloc and memcpy Sakari Ailus <sakari.ailus@iki.fi> - 2017-07-09 22:00 +0200
Re: [PATCH v2] staging: atomisp: use kstrdup to replace kmalloc and memcpy hari prasath <gehariprasath@gmail.com> - 2017-07-10 08:30 +0200
csiph-web