aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorMarek BehĂșn <marek.behun@nic.cz>2021-10-05 15:56:01 +0200
committerJagan Teki <jagan@amarulasolutions.com>2021-10-23 15:47:33 +0530
commita67b3719f32673a9890700c72b980acbd2749e49 (patch)
tree5dce2746635da38ef9d1ab95dca4e6f5ac582941 /include
parentf57277997bd8036d45337ec60b08a025a0473f89 (diff)
downloadu-boot-a67b3719f32673a9890700c72b980acbd2749e49.zip
u-boot-a67b3719f32673a9890700c72b980acbd2749e49.tar.gz
u-boot-a67b3719f32673a9890700c72b980acbd2749e49.tar.bz2
mtd: spi-flash: Check for zero length in legacy spi_flash_*()
Check for zero length in the legacy spi_flash_read() / spi_flash_write() / spi_flash_erase() functions. On zero length, return 0 immediately, don't call the underlying method. Rationale: - these legacy functions call the _read(), _write() and _erase() methods of struct mtd - the DM callers of these methods already check for zero length - making all callers of these methods check for zero length makes it possible to remove the check from implementations of these _read(), _write() and _erase() methods Signed-off-by: Marek BehĂșn <marek.behun@nic.cz>
Diffstat (limited to 'include')
-rw-r--r--include/spi_flash.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/include/spi_flash.h b/include/spi_flash.h
index 3d747c9..4d4ae89 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -165,6 +165,9 @@ static inline int spi_flash_read(struct spi_flash *flash, u32 offset,
struct mtd_info *mtd = &flash->mtd;
size_t retlen;
+ if (!len)
+ return 0;
+
return mtd->_read(mtd, offset, len, &retlen, buf);
}
@@ -174,6 +177,9 @@ static inline int spi_flash_write(struct spi_flash *flash, u32 offset,
struct mtd_info *mtd = &flash->mtd;
size_t retlen;
+ if (!len)
+ return 0;
+
return mtd->_write(mtd, offset, len, &retlen, buf);
}
@@ -188,6 +194,9 @@ static inline int spi_flash_erase(struct spi_flash *flash, u32 offset,
return -EINVAL;
}
+ if (!len)
+ return 0;
+
memset(&instr, 0, sizeof(instr));
instr.addr = offset;
instr.len = len;