Commit f636ffb4 authored by Atsushi Nemoto's avatar Atsushi Nemoto Committed by David Woodhouse

[MTD][MTDPART] Fix a division by zero bug

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: default avatarJörn Engel <joern@logfs.org>
Signed-off-by: default avatarAtsushi Nemoto <anemo@mba.ocn.ne.jp>
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent 6910c136
...@@ -411,11 +411,12 @@ static struct mtd_part *add_one_partition(struct mtd_info *master, ...@@ -411,11 +411,12 @@ static struct mtd_part *add_one_partition(struct mtd_info *master,
/* let's do some sanity checks */ /* let's do some sanity checks */
if (slave->offset >= master->size) { 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->offset = 0;
slave->mtd.size = 0; slave->mtd.size = 0;
printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n", printk(KERN_ERR"mtd: partition \"%s\" is out of reach -- disabled\n",
part->name); part->name);
goto out_register;
} }
if (slave->offset + slave->mtd.size > master->size) { if (slave->offset + slave->mtd.size > master->size) {
slave->mtd.size = master->size - slave->offset; slave->mtd.size = master->size - slave->offset;
...@@ -475,6 +476,7 @@ static struct mtd_part *add_one_partition(struct mtd_info *master, ...@@ -475,6 +476,7 @@ static struct mtd_part *add_one_partition(struct mtd_info *master,
} }
} }
out_register:
if (part->mtdp) { if (part->mtdp) {
/* store the object pointer (caller may or may not register it*/ /* store the object pointer (caller may or may not register it*/
*part->mtdp = &slave->mtd; *part->mtdp = &slave->mtd;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment