From: Simon Glass Date: Thu, 4 May 2023 22:50:47 +0000 (-0600) Subject: sf: Guard against zero erasesize X-Git-Url: http://git.dujemihanovic.xyz/?a=commitdiff_plain;h=28afcb1e7f7d1b899514cbdb58fb658ee0b5c5a3;p=u-boot.git 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 Reviewed-by: Bin Meng --- diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index e192f97efd..de6516f106 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; }