[PATCH 09/13] sf: Guard against zero erasesize

Simon Glass sjg at chromium.org
Mon Mar 13 04:11:06 CET 2023


With tiny SPI flash the erasesize is 0 which can cause a divide-by-zero
error. Check for this and returns a proper error instead.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 drivers/mtd/spi/sf_probe.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
index e192f97efdc4..de6516f1065b 100644
--- a/drivers/mtd/spi/sf_probe.c
+++ b/drivers/mtd/spi/sf_probe.c
@@ -189,7 +189,8 @@ static int spi_flash_std_erase(struct udevice *dev, u32 offset, size_t len)
 	struct mtd_info *mtd = &flash->mtd;
 	struct erase_info instr;
 
-	if (offset % mtd->erasesize || len % mtd->erasesize) {
+	if (!mtd->erasesize ||
+	    (offset % mtd->erasesize || len % mtd->erasesize)) {
 		debug("SF: Erase offset/length not multiple of erase size\n");
 		return -EINVAL;
 	}
-- 
2.40.0.rc1.284.g88254d51c5-goog



More information about the U-Boot mailing list