* [PATCH] libmtd: avoid divide by zero
@ 2020-11-26 22:41 Chris Packham
2020-11-26 23:43 ` Richard Weinberger
0 siblings, 1 reply; 2+ messages in thread
From: Chris Packham @ 2020-11-26 22:41 UTC (permalink / raw)
To: david.oberhollenzer, miquel.raynal, richard, vigneshr
Cc: Chris Packham, linux-mtd
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@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;
mtd->type = type_str2int(mtd->type_str);
mtd->bb_allowed = !!(mtd->type == MTD_NANDFLASH ||
mtd->type == MTD_MLCNANDFLASH);
--
2.29.2
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] libmtd: avoid divide by zero
2020-11-26 22:41 [PATCH] libmtd: avoid divide by zero Chris Packham
@ 2020-11-26 23:43 ` Richard Weinberger
0 siblings, 0 replies; 2+ messages in thread
From: Richard Weinberger @ 2020-11-26 23:43 UTC (permalink / raw)
To: Chris Packham
Cc: Vignesh Raghavendra, Richard Weinberger, linux-mtd,
David Oberhollenzer, Miquel Raynal
On Thu, Nov 26, 2020 at 11:48 PM Chris Packham
<chris.packham@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@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
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-11-26 23:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-26 22:41 [PATCH] libmtd: avoid divide by zero Chris Packham
2020-11-26 23:43 ` Richard Weinberger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).