aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Packham <chris.packham@alliedtelesis.co.nz>2020-11-27 13:07:08 +1300
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-11-29 23:39:41 +0100
commit54d68799b73e755923def1306b4da607ad45bd60 (patch)
treee5a96954da903dbc82b3be63b932b62015ad3f33
parent5a6e813a6ba48c81889208bdbeff92b13958dd2d (diff)
libmtd: avoid divide by zero
The concept of erase blocks doesn't apply to mtd-ram devices. Such devices set MTD_NO_ERASE to indicate this and some report 0 for the erase block size. Avoid a divide by zero when calculating the erase block count for such devices. Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz> Acked-by: Richard Weinberger <richard@nod.at> Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--lib/libmtd.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/libmtd.c b/lib/libmtd.c
index 9d8d0e8..b581d80 100644
--- a/lib/libmtd.c
+++ b/lib/libmtd.c
@@ -791,7 +791,10 @@ int mtd_get_dev_info1(libmtd_t desc, int mtd_num, struct mtd_dev_info *mtd)
return -1;
mtd->writable = !!(ret & MTD_WRITEABLE);
- mtd->eb_cnt = mtd->size / mtd->eb_size;
+ if (ret & MTD_NO_ERASE)
+ mtd->eb_cnt = 1;
+ else
+ mtd->eb_cnt = mtd->size / mtd->eb_size;
mtd->type = type_str2int(mtd->type_str);
mtd->bb_allowed = !!(mtd->type == MTD_NANDFLASH ||
mtd->type == MTD_MLCNANDFLASH);