2018-01-06 12:45:14

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 0/3] mtd/nftlmount: Adjustments for seven function implementations

From: Markus Elfring <[email protected]>
Date: Sat, 6 Jan 2018 13:38:32 +0100

Three update suggestions were taken into account
from static source code analysis.

Markus Elfring (3):
Delete two error messages for a failed memory allocation in find_boot_record()
Delete eight unwanted spaces behind function names
Add some spaces for better code readability

drivers/mtd/nftlmount.c | 36 +++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)

--
2.15.1


2018-01-06 12:46:15

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 1/3] mtd/nftlmount: Delete two error messages for a failed memory allocation in find_boot_record()

From: Markus Elfring <[email protected]>
Date: Sat, 6 Jan 2018 11:04:59 +0100

Omit extra messages for a memory allocation failure in this function.

This issue was detected by using the Coccinelle software.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/mtd/nftlmount.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
index 184c8fbfe465..6b9634a70229 100644
--- a/drivers/mtd/nftlmount.c
+++ b/drivers/mtd/nftlmount.c
@@ -201,15 +201,12 @@ device is already correct.

/* memory alloc */
nftl->EUNtable = kmalloc(nftl->nb_blocks * sizeof(u16), GFP_KERNEL);
- if (!nftl->EUNtable) {
- printk(KERN_NOTICE "NFTL: allocation of EUNtable failed\n");
+ if (!nftl->EUNtable)
return -ENOMEM;
- }

nftl->ReplUnitTable = kmalloc(nftl->nb_blocks * sizeof(u16), GFP_KERNEL);
if (!nftl->ReplUnitTable) {
kfree(nftl->EUNtable);
- printk(KERN_NOTICE "NFTL: allocation of ReplUnitTable failed\n");
return -ENOMEM;
}

--
2.15.1

2018-01-06 12:47:16

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 2/3] mtd/nftlmount: Delete eight unwanted spaces behind function names

From: Markus Elfring <[email protected]>
Date: Sat, 6 Jan 2018 12:55:23 +0100

The script "checkpatch.pl" pointed information out like the following.

WARNING: space prohibited between function name and open parenthesis '('

Thus fix the affected source code places.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/mtd/nftlmount.c | 23 ++++++++++++++---------
1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
index 6b9634a70229..d1eaa87c88ba 100644
--- a/drivers/mtd/nftlmount.c
+++ b/drivers/mtd/nftlmount.c
@@ -314,7 +314,7 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block)
8, &retlen, (char *)&uci) < 0)
goto default_uci1;

- erase_mark = le16_to_cpu ((uci.EraseMark | uci.EraseMark1));
+ erase_mark = le16_to_cpu(uci.EraseMark | uci.EraseMark1);
if (erase_mark != ERASE_MARK) {
default_uci1:
uci.EraseMark = cpu_to_le16(ERASE_MARK);
@@ -501,11 +501,12 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
&retlen, (char *)&h1) < 0)
return -1;

- erase_mark = le16_to_cpu ((h1.EraseMark | h1.EraseMark1));
+ erase_mark = le16_to_cpu(h1.EraseMark | h1.EraseMark1);
if (erase_mark != ERASE_MARK) {
/* if no erase mark, the block must be totally free. This is
possible in two cases : empty filesystem or interrupted erase (very unlikely) */
- if (check_free_sectors (nftl, block * nftl->EraseSize, nftl->EraseSize, 1) != 0)
+ if (check_free_sectors(nftl, block * nftl->EraseSize,
+ nftl->EraseSize, 1) != 0)
return -1;

/* free block : write erase mark */
@@ -521,8 +522,9 @@ static int check_and_mark_free_block(struct NFTLrecord *nftl, int block)
/* if erase mark present, need to skip it when doing check */
for (i = 0; i < nftl->EraseSize; i += SECTORSIZE) {
/* check free sector */
- if (check_free_sectors (nftl, block * nftl->EraseSize + i,
- SECTORSIZE, 0) != 0)
+ if (check_free_sectors(nftl,
+ block * nftl->EraseSize + i,
+ SECTORSIZE, 0) != 0)
return -1;

if (nftl_read_oob(mtd, block * nftl->EraseSize + i,
@@ -608,10 +610,13 @@ int NFTL_mount(struct NFTLrecord *s)
break;
}

- logical_block = le16_to_cpu ((h0.VirtUnitNum | h0.SpareVirtUnitNum));
- rep_block = le16_to_cpu ((h0.ReplUnitNum | h0.SpareReplUnitNum));
- nb_erases = le32_to_cpu (h1.WearInfo);
- erase_mark = le16_to_cpu ((h1.EraseMark | h1.EraseMark1));
+ logical_block = le16_to_cpu(h0.VirtUnitNum |
+ h0.SpareVirtUnitNum);
+ rep_block = le16_to_cpu(h0.ReplUnitNum |
+ h0.SpareReplUnitNum);
+ nb_erases = le32_to_cpu(h1.WearInfo);
+ erase_mark = le16_to_cpu(h1.EraseMark |
+ h1.EraseMark1);

is_first_block = !(logical_block >> 15);
logical_block = logical_block & 0x7fff;
--
2.15.1

2018-01-06 12:48:13

by SF Markus Elfring

[permalink] [raw]
Subject: [PATCH 3/3] mtd/nftlmount: Add some spaces for better code readability

From: Markus Elfring <[email protected]>
Date: Sat, 6 Jan 2018 12:58:37 +0100

Use space characters at some source code places according to
the Linux coding style convention.

Signed-off-by: Markus Elfring <[email protected]>
---
drivers/mtd/nftlmount.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
index d1eaa87c88ba..457f3572c582 100644
--- a/drivers/mtd/nftlmount.c
+++ b/drivers/mtd/nftlmount.c
@@ -253,7 +253,7 @@ The new DiskOnChip driver already scanned the bad block table. Just query it.

} /* foreach (block) */

- return boot_record_count?0:-1;
+ return boot_record_count ? 0 : -1;
}

static int memcmpb(void *a, int c, int n)
@@ -282,8 +282,8 @@ static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int
return -1;

if (check_oob) {
- if(nftl_read_oob(mtd, address, mtd->oobsize,
- &retlen, &buf[SECTORSIZE]) < 0)
+ if (nftl_read_oob(mtd, address, mtd->oobsize,
+ &retlen, &buf[SECTORSIZE]) < 0)
return -1;
if (memcmpb(buf + SECTORSIZE, 0xff, mtd->oobsize) != 0)
return -1;
@@ -389,7 +389,7 @@ static void check_sectors_in_chain(struct NFTLrecord *nftl, unsigned int first_b
else
status = bci.Status | bci.Status1;

- switch(status) {
+ switch (status) {
case SECTOR_FREE:
/* verify that the sector is really free. If not, mark
as ignore */
--
2.15.1