mtg: docg3: potential divide by zero in doc_write_oob()
PATCH 1/1 mtg: docg3: potential divide by zero in doc_write_oob()
If we set oobdelta to zero then we will either return -EINVAL or hit a divide (modulus) by zero on the next line when we check "(ooblen % oobdelta)". It's better to just return -EINVAL here instead.
---
Static analysis. I don't know if it's actually possible to hit this condition.
drivers/mtd/devices/docg3.c +1 -1
@@ -1440,7 +1440,7 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, oobdelta = mtd->ecclayout->oobavail;break ;default : - oobdelta =0 ; +return -EINVAL ; }if ((len %DOC_LAYOUT_PAGE_SIZE ) || (ooblen % oobdelta) || (ofs %DOC_LAYOUT_PAGE_SIZE ))
Quoted 8 lines · Dan Carpenter
If we set oobdelta to zero then we will either return
-EINVALor hit a divide (modulus) by zero on the next line when we check "(ooblen % oobdelta)". It's better to just return-EINVALhere instead.Signed-off-by Dan Carpenter <[email protected]>---
Static analysis. I don't know if it's actually possible to hit this condition.
I don't know any possibility to reach that condition, nonetheless the patch makes the code more robust, therefore :
Cheers.
--
Robert
Artem Bityutskiy
AppliedQuoted 5 lines · Dan Carpenter
If we set oobdelta to zero then we will either return
-EINVALor hit a divide (modulus) by zero on the next line when we check "(ooblen % oobdelta)". It's better to just return-EINVALhere instead.Signed-off-by Dan Carpenter <[email protected]>
Pushed to l2-mtd.git, thanks!
Signature · 2 lines
Best Regards, Artem Bityutskiy