mtg: docg3: potential divide by zero in doc_write_oob()
authorDan Carpenter <dan.carpenter@oracle.com>
Thu, 29 Nov 2012 14:16:51 +0000 (17:16 +0300)
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>
Mon, 10 Dec 2012 13:28:49 +0000 (15:28 +0200)
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>
Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
drivers/mtd/devices/docg3.c

index d34d83b8f9c22347da339e52b9071b5c1b8f9e2c..8510ccb9c6f00a450ed58cea115dd33d8070f749 100644 (file)
@@ -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))