From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751442AbdBDVdP (ORCPT ); Sat, 4 Feb 2017 16:33:15 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:35054 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751033AbdBDVdO (ORCPT ); Sat, 4 Feb 2017 16:33:14 -0500 Subject: Re: [PATCH] mtd: pmcmsp: use kstrndup instead of kmalloc+strncpy To: Arnd Bergmann , Brian Norris References: <20170203094946.2112158-1-arnd@arndb.de> Cc: David Woodhouse , Boris Brezillon , Richard Weinberger , Cyrille Pitchen , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org From: Marek Vasut Message-ID: <0e6b1dc1-5311-91ba-10e3-1a13f866df6b@gmail.com> Date: Sat, 4 Feb 2017 22:12:35 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0 MIME-Version: 1.0 In-Reply-To: <20170203094946.2112158-1-arnd@arndb.de> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/03/2017 10:49 AM, Arnd Bergmann wrote: > kernelci.org reports a warning for this driver, as it copies a local > variable into a 'const char *' string: > > drivers/mtd/maps/pmcmsp-flash.c:149:30: warning: passing argument 1 of 'strncpy' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] > > Using kstrndup() simplifies the code and avoids the warning. > > Signed-off-by: Arnd Bergmann Acked-by: Marek Vasut > --- > drivers/mtd/maps/pmcmsp-flash.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/drivers/mtd/maps/pmcmsp-flash.c b/drivers/mtd/maps/pmcmsp-flash.c > index f9fa3fad728e..2051f28ddac6 100644 > --- a/drivers/mtd/maps/pmcmsp-flash.c > +++ b/drivers/mtd/maps/pmcmsp-flash.c > @@ -139,15 +139,13 @@ static int __init init_msp_flash(void) > } > > msp_maps[i].bankwidth = 1; > - msp_maps[i].name = kmalloc(7, GFP_KERNEL); > + msp_maps[i].name = kstrndup(flash_name, 7, GFP_KERNEL); > if (!msp_maps[i].name) { > iounmap(msp_maps[i].virt); > kfree(msp_parts[i]); > goto cleanup_loop; > } > > - msp_maps[i].name = strncpy(msp_maps[i].name, flash_name, 7); > - > for (j = 0; j < pcnt; j++) { > part_name[5] = '0' + i; > part_name[7] = '0' + j; > -- Best regards, Marek Vasut