[PATCH v2 03/18] sf: Guard against zero erasesize

Simon Glass sjg at chromium.org
Tue Apr 18 17:30:46 CEST 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>
---

(no changes since v1)

 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.634.g4ca3ef3211-goog



More information about the U-Boot mailing list