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

* Re: [patch] mtg: docg3: potential divide by zero in doc_write_oob()
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Robert Jarzmik @ 2012-11-29 18:46 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Mike Dunn, Artem Bityutskiy, kernel-janitors, linux-mtd,
	Ivan Djelic, David Woodhouse

Dan Carpenter <dan.carpenter@oracle.com> writes:

> 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.
I don't know any possibility to reach that condition, nonetheless the patch
makes the code more robust, therefore :

Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>

Cheers.

--
Robert

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

* Re: [patch] mtg: docg3: potential divide by zero in doc_write_oob()
  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
  1 sibling, 0 replies; 3+ messages in thread
From: Artem Bityutskiy @ 2012-12-10 13:28 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Mike Dunn, David Woodhouse, kernel-janitors, linux-mtd,
	Ivan Djelic, Robert Jarzmik

[-- Attachment #1: Type: text/plain, Size: 402 bytes --]

On Thu, 2012-11-29 at 17:16 +0300, Dan Carpenter wrote:
> 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>

Pushed to l2-mtd.git, thanks!

-- 
Best Regards,
Artem Bityutskiy

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[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).