Skip to contentSkip to conversation

mtd: spi-nor-core: Fix static checker warnings

PATCH New Vignesh Raghavendra 1 participant 1 message Nov 9, 2019 Memory technology devices (MTD)

lore
Share & tools
lore

Vignesh Raghavendra

author maintainer
#0 lore raw

PATCH 1/1 mtd: spi-nor-core: Fix static checker warnings

Static checker warns 'ret' variable may be used uninitialized in spi_nor_erase() and spi_nor_write() in case of zero length requests. Fix these warnings by checking for zero length requests and returning early.

---
 drivers/mtd/spi/spi-nor-core.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/mtd/spi/spi-nor-core.c +6 -0
index 9b726be5d22d..87bcb63347ce 100644
@@ -550,6 +550,9 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr)
 	dev_dbg(nor->dev, "at 0x%llx, len %lld\n", (long long)instr->addr,
 		(long long)instr->len);
 
+	if (!instr->len)
+		return 0;
+
 	div_u64_rem(instr->len, mtd->erasesize, &rem);
 	if (rem)
 		return -EINVAL;
@@ -1230,6 +1233,9 @@ static int spi_nor_write(struct mtd_info *mtd, loff_t to, size_t len,
 
 	dev_dbg(nor->dev, "to 0x%08x, len %zd\n", (u32)to, len);
 
+	if (!len)
+		return 0;
+
 	for (i = 0; i < len; ) {
 		ssize_t written;
 		loff_t addr = to + i;
Signature · 1 line
2.24.0