From 54d68799b73e755923def1306b4da607ad45bd60 Mon Sep 17 00:00:00 2001 From: Chris Packham Date: Fri, 27 Nov 2020 13:07:08 +1300 Subject: 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 Acked-by: Richard Weinberger Signed-off-by: David Oberhollenzer --- lib/libmtd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib') 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); -- cgit v1.2.3