[PATCH] libmtd: avoid divide by zero
Richard Weinberger
richard.weinberger at gmail.com
Thu Nov 26 18:43:41 EST 2020
On Thu, Nov 26, 2020 at 11:48 PM Chris Packham
<chris.packham at alliedtelesis.co.nz> wrote:
> Some mtd-ram devices 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 at alliedtelesis.co.nz>
> ---
> lib/libmtd.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/lib/libmtd.c b/lib/libmtd.c
> index 9d8d0e8..8aa1cb1 100644
> --- a/lib/libmtd.c
> +++ b/lib/libmtd.c
> @@ -791,7 +791,8 @@ 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 (mtd->eb_size)
> + mtd->eb_cnt = mtd->size / mtd->eb_size;
I think it is better to check for MTD_NO_ERASE.
->eb_size is only allowed to be zero if MTD_NO_ERASE is set.
In that case we can configure mtd->eb_cnt to 1.
--
Thanks,
//richard
More information about the linux-mtd
mailing list