sf: Guard against zero erasesize

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

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
This commit is contained in:
Simon Glass 2023-05-04 16:50:47 -06:00 committed by Bin Meng
parent f2fac8b557
commit 28afcb1e7f

View file

@ -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 mtd_info *mtd = &flash->mtd;
struct erase_info instr; 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"); debug("SF: Erase offset/length not multiple of erase size\n");
return -EINVAL; return -EINVAL;
} }