[PATCH 1/2] mtdpart: Avoid divide-by-zero on out-of-reach path

Jörn Engel joern at logfs.org
Wed Jun 18 13:54:46 EDT 2008


[PATCH 0/4] [MTD][MTDPART] Fix a division by zero bug

Spotted and debugged by Atsushi Nemoto <anemo at mba.ocn.ne.jp>

When detecting a partition beyond the end of the device, skip most of
the initialisation, in particular those bits causing a division by zero.

Signed-off-by: Joern Engel <joern at logfs.org>
---
 drivers/mtd/mtdpart.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index c1a8916..bd51dba 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -420,11 +420,12 @@ static int add_one_partition(struct mtd_info *master,
 
 	/* let's do some sanity checks */
 	if (slave->offset >= master->size) {
-			/* let's register it anyway to preserve ordering */
+		/* let's register it anyway to preserve ordering */
 		slave->offset = 0;
 		slave->mtd.size = 0;
 		printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n",
 			part->name);
+		goto out_register;
 	}
 	if (slave->offset + slave->mtd.size > master->size) {
 		slave->mtd.size = master->size - slave->offset;
@@ -484,6 +485,7 @@ static int add_one_partition(struct mtd_info *master,
 		}
 	}
 
+out_register:
 	if (part->mtdp) {
 		/* store the object pointer (caller may or may not register it*/
 		*part->mtdp = &slave->mtd;
-- 
1.5.3.5




More information about the linux-mtd mailing list