mtd: pmcmsp: use kstrndup instead of kmalloc+strncpy

Linux-MTD Mailing List linux-mtd at lists.infradead.org
Sun Feb 12 18:59:02 PST 2017


Gitweb:     http://git.infradead.org/?p=mtd-2.6.git;a=commit;h=906b268477bc03daaa04f739844c120fe4dbc991
Commit:     906b268477bc03daaa04f739844c120fe4dbc991
Parent:     56ff337ea433731fa5f04cf9901404705bbbb6e0
Author:     Arnd Bergmann <arnd at arndb.de>
AuthorDate: Fri Feb 3 10:49:17 2017 +0100
Committer:  Brian Norris <computersforpeace at gmail.com>
CommitDate: Wed Feb 8 13:15:49 2017 -0800

    mtd: pmcmsp: use kstrndup instead of kmalloc+strncpy
    
    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 <arnd at arndb.de>
    Acked-by: Marek Vasut <marek.vasut at gmail.com>
    Signed-off-by: Brian Norris <computersforpeace at gmail.com>
---
 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 f9fa3fa..2051f28 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;



More information about the linux-mtd-cvs mailing list