CRIS v32: Adjustments for crisv32_nand_flash_probe()
cover CRIS v32: Adjustments for crisv32_nand_flash_probe()
From: Markus Elfring <[email protected]>
Date: Wed, 4 Oct 2017 20:33:20 +0200
A few update suggestions were taken into account
from static source code analysis.
Markus Elfring (5):
Delete an error message for a failed memory allocation Improve a size determination
Delete a jump target
Delete an unnecessary local variable
Split a condition check
arch/cris/arch-v32/drivers/mach-a3/nandflash.c | 17 ++++---------- arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 31 ++++++++++++-------------- 2 files changed, 18 insertions(+), 30 deletions(-)
Signature · 1 line
2.14.2
PATCH 1/5 cris: nand: Delete an error message for a failed memory allocation in crisv32_nand_flash_probe()
From: Markus Elfring <[email protected]>
Date: Wed, 4 Oct 2017 17:54:11 +0200
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
--- arch/cris/arch-v32/drivers/mach-a3/nandflash.c | 2 -- arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 2 -- 2 files changed, 4 deletions(-)
arch/cris/arch-v32/drivers/mach-a3/nandflash.c +0 -2
@@ -136,8 +136,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Allocate memory for MTD device structure and private data */ wrapper =kzalloc (sizeof (struct mtd_info_wrapper ),GFP_KERNEL );if (!wrapper) { -printk (KERN_ERR "Unable to allocate CRISv32 NAND MTD " -"device structure.\n" ); err = -ENOMEM ;return NULL ; }
arch/cris/arch-v32/drivers/mach-fs/nandflash.c +0 -2
@@ -111,8 +111,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Allocate memory for MTD device structure and private data */ wrapper =kzalloc (sizeof (struct mtd_info_wrapper ),GFP_KERNEL );if (!wrapper) { -printk (KERN_ERR "Unable to allocate CRISv32 NAND MTD " -"device structure.\n" ); err = -ENOMEM ;return NULL ; }
Signature · 1 line
2.14.2
PATCH 2/5 cris: nand: Improve a size determination in crisv32_nand_flash_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 4 Oct 2017 18:00:33 +0200
Replace the specification of a data structure by a pointer dereference as the parameter for the operator "sizeof" to make the corresponding size determination a bit safer according to the Linux coding style convention.
This issue was detected by using the Coccinelle software.
--- arch/cris/arch-v32/drivers/mach-a3/nandflash.c | 2 +- arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
arch/cris/arch-v32/drivers/mach-a3/nandflash.c +1 -1
@@ -134,7 +134,7 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)REG_WR (pio, regi_pio, rw_oe, oe);/* Allocate memory for MTD device structure and private data */ - wrapper =kzalloc (sizeof (struct mtd_info_wrapper ),GFP_KERNEL ); + wrapper =kzalloc (sizeof (*wrapper),GFP_KERNEL );if (!wrapper) { err = -ENOMEM ;return NULL ;
arch/cris/arch-v32/drivers/mach-fs/nandflash.c +1 -1
@@ -109,7 +109,7 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)int err =0 ;/* Allocate memory for MTD device structure and private data */ - wrapper =kzalloc (sizeof (struct mtd_info_wrapper ),GFP_KERNEL ); + wrapper =kzalloc (sizeof (*wrapper),GFP_KERNEL );if (!wrapper) { err = -ENOMEM ;return NULL ;
Signature · 1 line
2.14.2
PATCH 3/5 cris: nand: Delete a jump target in crisv32_nand_flash_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 4 Oct 2017 18:55:01 +0200
* Move a bit of exception handling code into an if branch because the code was used only for one case before.
* Delete the jump target "out_mtd" which became unnecessary with this refactoring.
--- arch/cris/arch-v32/drivers/mach-a3/nandflash.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
arch/cris/arch-v32/drivers/mach-a3/nandflash.c +2 -5
@@ -163,13 +163,10 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Scan to find existence of the device */ if (nand_scan (crisv32_mtd,1 )) { err = -ENXIO ; - goto out_mtd; +kfree (wrapper); +return NULL ; }return crisv32_mtd; - -out_mtd: -kfree (wrapper); -return NULL ; }
Signature · 1 line
2.14.2
PATCH 4/5 cris: nand: Delete an unnecessary local variable in crisv32_nand_flash_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 4 Oct 2017 19:32:18 +0200
The local variable "err" was never read in this function. Thus remove it.
--- arch/cris/arch-v32/drivers/mach-a3/nandflash.c | 6 +----- arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 10 ++-------- 2 files changed, 3 insertions(+), 13 deletions(-)
arch/cris/arch-v32/drivers/mach-a3/nandflash.c +1 -5
@@ -108,7 +108,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)struct mtd_info_wrapper *wrapper;struct nand_chip *this; -int err =0 ;reg_pio_rw_man_ctrl man_ctrl = { .regf_NCE = regk_pio_yes,
@@ -135,10 +134,8 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Allocate memory for MTD device structure and private data */ wrapper =kzalloc (sizeof (*wrapper),GFP_KERNEL ); -if (!wrapper) { - err = -ENOMEM ; +if (!wrapper)return NULL ; - } read_cs = write_cs = (void __iomem *)REG_ADDR (pio, regi_pio, rw_io_access0);
@@ -162,7 +159,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Scan to find existence of the device */ if (nand_scan (crisv32_mtd,1 )) { - err = -ENXIO ;kfree (wrapper);return NULL ; }
arch/cris/arch-v32/drivers/mach-fs/nandflash.c +2 -8
@@ -106,21 +106,17 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)reg_gio_rw_pa_oe pa_oe =REG_RD (gio, regi_gio, rw_pa_oe);struct mtd_info_wrapper *wrapper;struct nand_chip *this; -int err =0 ;/* Allocate memory for MTD device structure and private data */ wrapper =kzalloc (sizeof (*wrapper),GFP_KERNEL ); -if (!wrapper) { - err = -ENOMEM ; +if (!wrapper)return NULL ; - } read_cs =ioremap (MEM_CSP0_START |MEM_NON_CACHEABLE ,8192 ); write_cs =ioremap (MEM_CSP1_START |MEM_NON_CACHEABLE ,8192 );if (!read_cs || !write_cs) {printk (KERN_ERR "CRISv32 NAND ioremap failed\n" ); - err = -EIO ; goto out_mtd; }
@@ -152,10 +148,8 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* this->bbt_options = NAND_BBT_USE_FLASH; */ /* Scan to find existence of the device */ -if (nand_scan (crisv32_mtd,1 )) { - err = -ENXIO ; +if (nand_scan (crisv32_mtd,1 )) goto out_ior; - }return crisv32_mtd;
Signature · 1 line
2.14.2
PATCH 5/5 cris: nand: Split a condition check in crisv32_nand_flash_probe()
In reply to SF Markus ElfringFrom: Markus Elfring <[email protected]>
Date: Wed, 4 Oct 2017 20:02:12 +0200
* Split a condition check for failed calls of the function "ioremap" so that the return value in the variable "write_cs" will also be immediately checked.
* Adjust jump targets according to the Linux coding style convention.
--- arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
arch/cris/arch-v32/drivers/mach-fs/nandflash.c +11 -6
@@ -113,13 +113,17 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)return NULL ; read_cs =ioremap (MEM_CSP0_START |MEM_NON_CACHEABLE ,8192 ); - write_cs =ioremap (MEM_CSP1_START |MEM_NON_CACHEABLE ,8192 ); - -if (!read_cs || !write_cs) { +if (!read_cs) {printk (KERN_ERR "CRISv32 NAND ioremap failed\n" ); goto out_mtd; } + write_cs =ioremap (MEM_CSP1_START |MEM_NON_CACHEABLE ,8192 ); +if (!write_cs) { +printk (KERN_ERR "CRISv32 NAND ioremap failed\n" ); + goto unmap_read; + } +/* Get pointer to private data */ this = &wrapper->chip; crisv32_mtd =nand_to_mtd (this);
@@ -149,13 +153,14 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Scan to find existence of the device */ if (nand_scan (crisv32_mtd,1 )) - goto out_ior; + goto unmap_io;return crisv32_mtd; -out_ior: -iounmap ((void *)read_cs); +unmap_io:iounmap ((void *)write_cs); +unmap_read: +iounmap ((void *)read_cs); out_mtd:kfree (wrapper);return NULL ;
Signature · 1 line
2.14.2
Re: [PATCH 1/5] cris: nand: Delete an error message for a failed memory allocation in crisv32_nand_flash_probe()
In reply to SF Markus ElfringHello Markus,
Quoted 3 lines · On Wed, 4 Oct 2017 20:45:14 +0200 SF Markus Elfring…
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
what exactly has the software detected?
I cannot find, how this error is reported otherwise, it seems to me that the message is not that superflous.
The patches 2..4 look to me as an exercise without any practical meaning. Indeed, that's not how new code should be posted, but if we start rewriting all the legacy code, this will produce huge and completely unnecessary patch traffic.
Quoted 32 lines
Signed-off-by Markus Elfring <[email protected]>--- arch/cris/arch-v32/drivers/mach-a3/nandflash.c | 2 -- arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 2 -- 2 files changed, 4 deletions(-)arch/cris/arch-v32/drivers/mach-a3/nandflash.c +0
-2@@ -136,8 +136,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Allocate memory for MTD device structure and private data */ wrapper =kzalloc (sizeof (struct mtd_info_wrapper ),GFP_KERNEL );if (!wrapper) { -printk (KERN_ERR "Unable to allocate CRISv32 NAND MTD " -"device structure.\n" ); err = -ENOMEM ;return NULL ; }arch/cris/arch-v32/drivers/mach-fs/nandflash.c +0
-2@@ -111,8 +111,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Allocate memory for MTD device structure and private data */ wrapper =kzalloc (sizeof (struct mtd_info_wrapper ),GFP_KERNEL );if (!wrapper) { -printk (KERN_ERR "Unable to allocate CRISv32 NAND MTD " -"device structure.\n" ); err = -ENOMEM ;return NULL ; }
Signature · 1 line
Alexander Sverdlin.
Re: cris: nand: Delete an error message for a failed memory allocation in crisv32_nand_flash_probe()
Quoted 5 lines
Quoted 3 lines
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
what exactly has the software detected?
Do you prefer the notification “WARNING: Possible unnecessary 'out of memory' message” by the script “checkpatch.pl” instead?
Quoted 2 lines
I cannot find, how this error is reported otherwise, it seems to me that the message is not that superflous.
Would you find the default allocation failure report sufficient?
Regards,
Markus
Re: [PATCH 1/5] cris: nand: Delete an error message for a failed memory allocation in crisv32_nand_flash_probe()
In reply to Alexander SverdlinQuoted 9 lines · Alexander Sverdlin
Hello Markus,
Quoted 3 lines · On Wed, 4 Oct 2017 20:45:14 +0200 SF Markus Elfring…
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Quoted 8 lines
what exactly has the software detected?
I cannot find, how this error is reported otherwise, it seems to me that the message is not that superflous.The patches 2..4 look to me as an exercise without any practical meaning. Indeed, that's not how new code should be posted, but if we start rewriting all the legacy code, this will produce huge and completely unnecessary patch traffic.
kmalloc etc will produce a backtrace on failure that will provide essentially the same information.
I don't know what was in the other patches, but the useless assignments to err in these functions are perhaps worth fixing.
julia
Quoted 41 lines
Quoted 25 lines
Signed-off-by Markus Elfring <[email protected]>--- arch/cris/arch-v32/drivers/mach-a3/nandflash.c | 2 -- arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 2 -- 2 files changed, 4 deletions(-)arch/cris/arch-v32/drivers/mach-a3/nandflash.c +0
-2@@ -136,8 +136,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Allocate memory for MTD device structure and private data */ wrapper =kzalloc (sizeof (struct mtd_info_wrapper ),GFP_KERNEL );if (!wrapper) { -printk (KERN_ERR "Unable to allocate CRISv32 NAND MTD " -"device structure.\n" ); err = -ENOMEM ;return NULL ; }arch/cris/arch-v32/drivers/mach-fs/nandflash.c +0
-0arch/cris/arch-v32/drivers/mach-fs/nandflash.c struct mtd_info *__init crisv32_nand_flash_probe(void) · line 116
Quoted 8 lines
arch/cris/arch-v32/drivers/mach-fs/nandflash.c +0
-2@@ -111,8 +111,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Allocate memory for MTD device structure and private data */ wrapper =kzalloc (sizeof (struct mtd_info_wrapper ),GFP_KERNEL );if (!wrapper) { -printk (KERN_ERR "Unable to allocate CRISv32 NAND MTD " -"device structure.\n" ); err = -ENOMEM ;return NULL ; }--
Alexander Sverdlin.
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 1/5] cris: nand: Delete an error message for a failed memory allocation in crisv32_nand_flash_probe()
In reply to SF Markus ElfringQuoted 5 lines · SF Markus Elfring
Omit an extra message for a memory allocation failure in this function.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Quoted 31 lines
--- arch/cris/arch-v32/drivers/mach-a3/nandflash.c | 2 -- arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 2 -- 2 files changed, 4 deletions(-)arch/cris/arch-v32/drivers/mach-a3/nandflash.c +0
-2@@ -136,8 +136,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Allocate memory for MTD device structure and private data */ wrapper =kzalloc (sizeof (struct mtd_info_wrapper ),GFP_KERNEL );if (!wrapper) { -printk (KERN_ERR "Unable to allocate CRISv32 NAND MTD " -"device structure.\n" ); err = -ENOMEM ;return NULL ; }arch/cris/arch-v32/drivers/mach-fs/nandflash.c +0
-2@@ -111,8 +111,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Allocate memory for MTD device structure and private data */ wrapper =kzalloc (sizeof (struct mtd_info_wrapper ),GFP_KERNEL );if (!wrapper) { -printk (KERN_ERR "Unable to allocate CRISv32 NAND MTD " -"device structure.\n" ); err = -ENOMEM ;return NULL ; }
Re: [PATCH 4/5] cris: nand: Delete an unnecessary local variable in crisv32_nand_flash_probe()
In reply to SF Markus ElfringQuoted 4 lines · SF Markus Elfring
The local variable "err" was never read in this function. Thus remove it.
Signed-off-by Markus Elfring <[email protected]>
Quoted 77 lines
--- arch/cris/arch-v32/drivers/mach-a3/nandflash.c | 6 +----- arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 10 ++-------- 2 files changed, 3 insertions(+), 13 deletions(-)arch/cris/arch-v32/drivers/mach-a3/nandflash.c +1
-5@@ -108,7 +108,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)struct mtd_info_wrapper *wrapper;struct nand_chip *this; -int err =0 ;reg_pio_rw_man_ctrl man_ctrl = { .regf_NCE = regk_pio_yes,@@ -135,10 +134,8 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Allocate memory for MTD device structure and private data */ wrapper =kzalloc (sizeof (*wrapper),GFP_KERNEL ); -if (!wrapper) { - err = -ENOMEM ; +if (!wrapper)return NULL ; - } read_cs = write_cs = (void __iomem *)REG_ADDR (pio, regi_pio, rw_io_access0);@@ -162,7 +159,6 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Scan to find existence of the device */ if (nand_scan (crisv32_mtd,1 )) { - err = -ENXIO ;kfree (wrapper);return NULL ; }arch/cris/arch-v32/drivers/mach-fs/nandflash.c +2
-8@@ -106,21 +106,17 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)reg_gio_rw_pa_oe pa_oe =REG_RD (gio, regi_gio, rw_pa_oe);struct mtd_info_wrapper *wrapper;struct nand_chip *this; -int err =0 ;/* Allocate memory for MTD device structure and private data */ wrapper =kzalloc (sizeof (*wrapper),GFP_KERNEL ); -if (!wrapper) { - err = -ENOMEM ; +if (!wrapper)return NULL ; - } read_cs =ioremap (MEM_CSP0_START |MEM_NON_CACHEABLE ,8192 ); write_cs =ioremap (MEM_CSP1_START |MEM_NON_CACHEABLE ,8192 );if (!read_cs || !write_cs) {printk (KERN_ERR "CRISv32 NAND ioremap failed\n" ); - err = -EIO ; goto out_mtd; }@@ -152,10 +148,8 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* this->bbt_options = NAND_BBT_USE_FLASH; */ /* Scan to find existence of the device */ -if (nand_scan (crisv32_mtd,1 )) { - err = -ENXIO ; +if (nand_scan (crisv32_mtd,1 )) goto out_ior; - }return crisv32_mtd;
Re: [PATCH 5/5] cris: nand: Split a condition check in crisv32_nand_flash_probe()
In reply to SF Markus ElfringHello Markus,
Quoted 23 lines · SF Markus Elfring
* Split a condition check for failed calls of the function "ioremap" so that the return value in the variable "
write_cs" will also be immediately checked.* Adjust jump targets according to the Linux coding style convention.
Signed-off-by Markus Elfring <[email protected]>--- arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)arch/cris/arch-v32/drivers/mach-fs/nandflash.c +1
-3@@ -113,13 +113,17 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)return NULL ; read_cs =ioremap (MEM_CSP0_START |MEM_NON_CACHEABLE ,8192 ); - write_cs =ioremap (MEM_CSP1_START |MEM_NON_CACHEABLE ,8192 ); - -if (!read_cs || !write_cs) { +if (!read_cs) {
arch/cris/arch-v32/drivers/mach-fs/nandflash.c struct mtd_info *__init crisv32_nand_flash_probe(void) · line 126
Quoted 10 lines
arch/cris/arch-v32/drivers/mach-fs/nandflash.c +6
-0printk (KERN_ERR "CRISv32 NAND ioremap failed\n" ); goto out_mtd; } + write_cs =ioremap (MEM_CSP1_START |MEM_NON_CACHEABLE ,8192 ); +if (!write_cs) { +printk (KERN_ERR "CRISv32 NAND ioremap failed\n" ); + goto unmap_read; + } +
Instead of duplicating the error message I'd rather put an "if" in the iounmap() path.
Quoted 8 lines
arch/cris/arch-v32/drivers/mach-fs/nandflash.c +0
-1/* Get pointer to private data */ this = &wrapper->chip; crisv32_mtd =nand_to_mtd (this);@@ -149,13 +153,14 @@ struct mtd_info *__init crisv32_nand_flash_probe(void)/* Scan to find existence of the device */ if (nand_scan (crisv32_mtd,1 )) - goto out_ior;
arch/cris/arch-v32/drivers/mach-fs/nandflash.c struct mtd_info *__init crisv32_nand_flash_probe(void) · line 163
Quoted 10 lines
arch/cris/arch-v32/drivers/mach-fs/nandflash.c +4
-2+ goto unmap_io;return crisv32_mtd; -out_ior: -iounmap ((void *)read_cs); +unmap_io:iounmap ((void *)write_cs); +unmap_read: +iounmap ((void *)read_cs);
I believe, (void *) casting is wrong, it does nothing than removing __iomem qualifier.
I'd rather write
if (read_cs)
iounmap(read_cs); if (write_cs) iounmap(write_cs);
Quoted 2 lines
arch/cris/arch-v32/drivers/mach-fs/nandflash.c +0
-0out_mtd:kfree (wrapper);
Hi Markus,
Quoted 5 lines · SF Markus Elfring
From: Markus Elfring <[email protected]>
Date: Wed, 4 Oct 2017 20:33:20 +0200A few update suggestions were taken into account
from static source code analysis.
If you plan to send a v2 could you remove me from the CC.
I know that ./scripts/get_maintainer.pl added my name but I am not related at all to this code. I just gave my acked-by for a part of patch which modified in the same time the file I care and many other files.
Thanks,
Greogry
Quoted 15 lines
Markus Elfring (5):
Delete an error message for a failed memory allocation Improve a size determination
Delete a jump target
Delete an unnecessary local variable
Split a condition checkarch/cris/arch-v32/drivers/mach-a3/nandflash.c | 17 ++++---------- arch/cris/arch-v32/drivers/mach-fs/nandflash.c | 31 ++++++++++++-------------- 2 files changed, 18 insertions(+), 30 deletions(-)Signature · 1 line
2.14.2
Signature · 4 lines
Gregory Clement, Free Electrons Kernel, drivers, real-time and embedded Linux development, consulting, training and support. http://free-electrons.com