Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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@arndb.de>
Acked-by: Marek Vasut <marek.vasut@gmail.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>

authored by

Arnd Bergmann and committed by
Brian Norris
906b2684 56ff337e

+1 -3
+1 -3
drivers/mtd/maps/pmcmsp-flash.c
··· 139 139 } 140 140 141 141 msp_maps[i].bankwidth = 1; 142 - msp_maps[i].name = kmalloc(7, GFP_KERNEL); 142 + msp_maps[i].name = kstrndup(flash_name, 7, GFP_KERNEL); 143 143 if (!msp_maps[i].name) { 144 144 iounmap(msp_maps[i].virt); 145 145 kfree(msp_parts[i]); 146 146 goto cleanup_loop; 147 147 } 148 - 149 - msp_maps[i].name = strncpy(msp_maps[i].name, flash_name, 7); 150 148 151 149 for (j = 0; j < pcnt; j++) { 152 150 part_name[5] = '0' + i;