]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sf: Guard against zero erasesize
authorSimon Glass <sjg@chromium.org>
Thu, 4 May 2023 22:50:47 +0000 (16:50 -0600)
committerBin Meng <bmeng@tinylab.org>
Thu, 11 May 2023 02:25:29 +0000 (10:25 +0800)
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>
drivers/mtd/spi/sf_probe.c

index e192f97efdc4f76ef5bca8d9b941ea31fdee57ab..de6516f1065be9fb106e71894f22f5ff34b0f2f0 100644 (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 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;
        }