Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1572981 > unrolled thread
| Started by | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| First post | 2017-02-03 11:00 +0100 |
| Last post | 2017-02-08 22:30 +0100 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
[PATCH] mtd: pmcmsp: use kstrndup instead of kmalloc+strncpy Arnd Bergmann <arnd@arndb.de> - 2017-02-03 11:00 +0100
Re: [PATCH] mtd: pmcmsp: use kstrndup instead of kmalloc+strncpy Marek Vasut <marek.vasut@gmail.com> - 2017-02-04 22:40 +0100
Re: [PATCH] mtd: pmcmsp: use kstrndup instead of kmalloc+strncpy Brian Norris <computersforpeace@gmail.com> - 2017-02-08 22:30 +0100
| From | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| Date | 2017-02-03 11:00 +0100 |
| Subject | [PATCH] mtd: pmcmsp: use kstrndup instead of kmalloc+strncpy |
| Message-ID | <t6IOS-8nh-25@gated-at.bofh.it> |
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>
---
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;
--
2.9.0
[toc] | [next] | [standalone]
| From | Marek Vasut <marek.vasut@gmail.com> |
|---|---|
| Date | 2017-02-04 22:40 +0100 |
| Message-ID | <t7gdP-6nu-3@gated-at.bofh.it> |
| In reply to | #1572981 |
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 <arnd@arndb.de>
Acked-by: Marek Vasut <marek.vasut@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 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
[toc] | [prev] | [next] | [standalone]
| From | Brian Norris <computersforpeace@gmail.com> |
|---|---|
| Date | 2017-02-08 22:30 +0100 |
| Message-ID | <t8HYm-5wK-35@gated-at.bofh.it> |
| In reply to | #1573758 |
On Sat, Feb 04, 2017 at 10:12:35PM +0100, Marek Vasut wrote: > 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 <arnd@arndb.de> > > Acked-by: Marek Vasut <marek.vasut@gmail.com> Applied to l2-mtd.git.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web