Return-Path: Received: from mail-by2nam01on0120.outbound.protection.outlook.com ([104.47.34.120]:44880 "EHLO NAM01-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932368AbeARU7p (ORCPT ); Thu, 18 Jan 2018 15:59:45 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Arnd Bergmann , Brian Norris , Sasha Levin Subject: [added to the 4.1 stable tree] mtd: pmcmsp: use kstrndup instead of kmalloc+strncpy Date: Thu, 18 Jan 2018 20:59:37 +0000 Message-ID: <20180118205908.3220-26-alexander.levin@microsoft.com> References: <20180118205908.3220-1-alexander.levin@microsoft.com> In-Reply-To: <20180118205908.3220-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Arnd Bergmann This patch has been added to the stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 906b268477bc03daaa04f739844c120fe4dbc991 ] 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 Signed-off-by: Brian Norris Signed-off-by: Sasha Levin --- 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-flas= h.c index 744ca5cacc9b..cf54420f943d 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) } =20 msp_maps[i].bankwidth =3D 1; - msp_maps[i].name =3D kmalloc(7, GFP_KERNEL); + msp_maps[i].name =3D kstrndup(flash_name, 7, GFP_KERNEL); if (!msp_maps[i].name) { iounmap(msp_maps[i].virt); kfree(msp_parts[i]); goto cleanup_loop; } =20 - msp_maps[i].name =3D strncpy(msp_maps[i].name, flash_name, 7); - for (j =3D 0; j < pcnt; j++) { part_name[5] =3D '0' + i; part_name[7] =3D '0' + j; --=20 2.11.0