Skip to contentSkip to conversation

mtd: small cleanups

PATCH In review Brian Norris 1 participant 8 messages May 21, 2014 – May 28, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover mtd: small cleanups

This series consists of miscellaneous fixes and cleanups, mostly caught through some sort of static analysis (gcc warnings, sparse, Coverity, etc.).

Brian Norris (6):
mtd: pfow: remove unused variable
mtd: slram: fix unused variable warning
mtd: maps: sc520cdp: fix warnings
mtd: nand_bbt: remove unused variable
mtd: nand_bbt: handle error case for nand_create_badblock_pattern()
mtd: nand: r852: correct write_buf loop bounds

 drivers/mtd/devices/slram.c |    4 +---
 drivers/mtd/maps/sc520cdp.c |    6 +++---
 drivers/mtd/nand/nand_bbt.c |   13 +++++++------
 drivers/mtd/nand/r852.c     |    6 ++++--
 include/linux/mtd/pfow.h    |    3 ---
 5 files changed, 15 insertions(+), 17 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/6 mtd: pfow: remove unused variable

Fixes warning:

In file included from drivers/mtd/lpddr/qinfo_probe.c:31:0:
include/linux/mtd/pfow.h: In function ‘send_pfow_command’:
include/linux/mtd/pfow.h:104:6: warning: variable ‘chipnum’ set but not used [-Wunused-but-set-variable]

  int chipnum;
      ^
---
 include/linux/mtd/pfow.h |    3 ---
 1 file changed, 3 deletions(-)
include/linux/mtd/pfow.h +0 -3
index b730d4f84655..42ff7ff09bf5 100644
@@ -101,9 +101,6 @@ static inline void send_pfow_command(struct map_info *map,
 				unsigned long len, map_word *datum)
 {
 	int bits_per_chip = map_bankwidth(map) * 8;
-	int chipnum;
-	struct lpddr_private *lpddr = map->fldrv_priv;
-	chipnum = adr >> lpddr->chipshift;
 
 	map_write(map, CMD(cmd_code), map->pfow_base + PFOW_COMMAND_CODE);
 	map_write(map, CMD(adr & ((1<<bits_per_chip) - 1)),
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/6 mtd: slram: fix unused variable warning

In reply to Brian Norris

drivers/mtd/devices/slram.c: In function 'init_slram':
drivers/mtd/devices/slram.c:283:6: warning: variable 'i' set but not used [-Wunused-but-set-variable]

---
 drivers/mtd/devices/slram.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mtd/devices/slram.c +1 -3
index 5a5cd2ace4a6..2fc4957cbe7f 100644
@@ -280,14 +280,11 @@ __setup("slram=", mtd_slram_setup);
 static int __init init_slram(void)
 {
 	char *devname;
-	int i;
 
 #ifndef MODULE
 	char *devstart;
 	char *devlength;
 
-	i = 0;
-
 	if (!map) {
 		E("slram: not enough parameters.\n");
 		return(-EINVAL);
@@ -314,6 +311,7 @@ static int __init init_slram(void)
 	}
 #else
 	int count;
+	int i;
 
 	for (count = 0; count < SLRAM_MAX_DEVICES_PARAMS && map[count];
 			count++) {
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 3/6 mtd: maps: sc520cdp: fix warnings

In reply to Brian Norris

On m86k, and maybe a few other architectures, we get this kind of warning, due to misuse of volatile:

drivers/mtd/maps/sc520cdp.c: In function 'sc520cdp_setup_par':

Quoted 1 line
Quoted 1 line

drivers/mtd/maps/sc520cdp.c:223:2: warning: passing argument 1 of 'iounmap' discards 'volatile' qualifier from pointer target type [enabled by default]

arch/m68k/include/asm/raw_io.h:22:13: note: expected 'void *' but argument is of type 'volatile long unsigned int *'

Rather than annotating the variable declaration, let's just use the proper accessors, which add the 'volatile' qualifier to the operation.

---
 drivers/mtd/maps/sc520cdp.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/mtd/maps/sc520cdp.c +3 -3
index 8fead8e46bce..093edd51bdc7 100644
@@ -183,7 +183,7 @@ static const struct sc520_par_table par_table[NUM_FLASH_BANKS] =
 
 static void sc520cdp_setup_par(void)
 {
-	volatile unsigned long __iomem *mmcr;
+	unsigned long __iomem *mmcr;
 	unsigned long mmcr_val;
 	int i, j;
 
@@ -203,11 +203,11 @@ static void sc520cdp_setup_par(void)
 	*/
 	for(i = 0; i < NUM_FLASH_BANKS; i++) {		/* for each par_table entry  */
 		for(j = 0; j < NUM_SC520_PAR; j++) {	/* for each PAR register     */
-			mmcr_val = mmcr[SC520_PAR(j)];
+			mmcr_val = readl(&mmcr[SC520_PAR(j)]);
 			/* if target device field matches, reprogram the PAR */
 			if((mmcr_val & SC520_PAR_TRGDEV) == par_table[i].trgdev)
 			{
-				mmcr[SC520_PAR(j)] = par_table[i].new_par;
+				writel(par_table[i].new_par, &mmcr[SC520_PAR(j)]);
 				break;
 			}
 		}
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH 4/6 mtd: nand_bbt: remove unused variable

In reply to Brian Norris

Set, but unused, variable.

---
 drivers/mtd/nand/nand_bbt.c |    5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/mtd/nand/nand_bbt.c +1 -4
index c0615d1526f9..6cbf8768a0a4 100644
@@ -528,7 +528,7 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
 {
 	struct nand_chip *this = mtd->priv;
 	int i, chips;
-	int bits, startblock, block, dir;
+	int startblock, block, dir;
 	int scanlen = mtd->writesize + mtd->oobsize;
 	int bbtblocks;
 	int blocktopage = this->bbt_erase_shift - this->page_shift;
@@ -552,9 +552,6 @@ static int search_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr
 		bbtblocks = mtd->size >> this->bbt_erase_shift;
 	}
 
-	/* Number of bits for each erase block in the bbt */
-	bits = td->options & NAND_BBT_NRBITS_MSK;
-
 	for (i = 0; i < chips; i++) {
 		/* Reset version information */
 		td->version[i] = 0;
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH 5/6 mtd: nand_bbt: handle error case for nand_create_badblock_pattern()

In reply to Brian Norris
---
 drivers/mtd/nand/nand_bbt.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/mtd/nand/nand_bbt.c +6 -2
index 6cbf8768a0a4..7f0c3b4c2a4f 100644
@@ -1282,6 +1282,7 @@ static int nand_create_badblock_pattern(struct nand_chip *this)
 int nand_default_bbt(struct mtd_info *mtd)
 {
 	struct nand_chip *this = mtd->priv;
+	int ret;
 
 	/* Is a flash based bad block table requested? */
 	if (this->bbt_options & NAND_BBT_USE_FLASH) {
@@ -1300,8 +1301,11 @@ int nand_default_bbt(struct mtd_info *mtd)
 		this->bbt_md = NULL;
 	}
 
-	if (!this->badblock_pattern)
-		nand_create_badblock_pattern(this);
+	if (!this->badblock_pattern) {
+		ret = nand_create_badblock_pattern(this);
+		if (ret)
+			return ret;
+	}
 
 	return nand_scan_bbt(mtd, this->badblock_pattern);
 }
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH 6/6 mtd: nand: r852: correct write_buf loop bounds

In reply to Brian Norris

The two loops in r852_write_buf() are designed to handle 4-byte-aligned and then 1-byte-aligned portions, respectively. However, there are two issues:

(1) The first loop will only terminate if 'len' is a multiple of 4
(2) The second loop will never terminate if it runs at least once

Rewrite these loops as they were probably intended. Compile tested only.

Issues pointed out by Coverity Scan.

Cc Maxim Levitsky <[email protected]>
---
 drivers/mtd/nand/r852.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/mtd/nand/r852.c +4 -2
index 325930db3f04..baea83f4dea8 100644
@@ -245,7 +245,7 @@ static void r852_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 	}
 
 	/* write DWORD chinks - faster */
-	while (len) {
+	while (len >= 4) {
 		reg = buf[0] | buf[1] << 8 | buf[2] << 16 | buf[3] << 24;
 		r852_write_reg_dword(dev, R852_DATALINE, reg);
 		buf += 4;
@@ -254,8 +254,10 @@ static void r852_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
 	}
 
 	/* write rest */
-	while (len)
+	while (len > 0) {
 		r852_write_reg(dev, R852_DATALINE, *buf++);
+		len--;
+	}
 }
 
 /*
Signature · 1 line
1.7.9.5
#7 lore raw
In reply to Brian Norris
Quoted 10 lines · Brian Norris

This series consists of miscellaneous fixes and cleanups, mostly caught through some sort of static analysis (gcc warnings, sparse, Coverity, etc.).

Brian Norris (6):
mtd: pfow: remove unused variable
mtd: slram: fix unused variable warning
mtd: maps: sc520cdp: fix warnings
mtd: nand_bbt: remove unused variable
mtd: nand_bbt: handle error case for nand_create_badblock_pattern()
mtd: nand: r852: correct write_buf loop bounds

Pushed all 6 to l2-mtd.git.

Brian