mtd: spi-nor-core: Fix static checker warnings
authorVignesh Raghavendra <vigneshr@ti.com>
Sat, 9 Nov 2019 06:34:13 +0000 (12:04 +0530)
committerJagan Teki <jagan@amarulasolutions.com>
Fri, 27 Dec 2019 12:17:26 +0000 (17:47 +0530)
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.

Reported-by: Dan Murphy <dmurphy@ti.com>
Signed-off-by: Vignesh Raghavendra <vigneshr@ti.com>
drivers/mtd/spi/spi-nor-core.c

index 5a8c084255662669930584bb2dbb0606be671d74..eb49a6c11c4030e94982b72adc015f03671c526b 100644 (file)
@@ -546,6 +546,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;
@@ -1226,6 +1229,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;