kernel-janitors.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] mtg: docg3: potential divide by zero in doc_write_oob()
@ 2012-11-29 14:16 Dan Carpenter
  2012-11-29 18:46 ` Robert Jarzmik
  2012-12-10 13:28 ` Artem Bityutskiy
  0 siblings, 2 replies; 3+ messages in thread
From: Dan Carpenter @ 2012-11-29 14:16 UTC (permalink / raw)
  To: David Woodhouse
  Cc: Mike Dunn, Artem Bityutskiy, kernel-janitors, linux-mtd,
	Ivan Djelic, Robert Jarzmik

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.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Static analysis.  I don't know if it's actually possible to hit this
condition.

diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c
index d34d83b..8510ccb 100644
--- a/drivers/mtd/devices/docg3.c
+++ b/drivers/mtd/devices/docg3.c
@@ -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))

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-12-10 13:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-29 14:16 [patch] mtg: docg3: potential divide by zero in doc_write_oob() Dan Carpenter
2012-11-29 18:46 ` Robert Jarzmik
2012-12-10 13:28 ` Artem Bityutskiy

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).