[PATCH 1/2] mtdpart: Avoid divide-by-zero on out-of-reach path
Atsushi Nemoto
anemo at mba.ocn.ne.jp
Mon Jun 16 10:32:22 EDT 2008
On "partition is out of reach" path, i.e. slave's offset was bigger
than the master's size, slave's erasesize will not be calculated and
it leads division by zero on following boundary checking. This patch
makes calculation of the slave's erasesize more robust.
Signed-off-by: Atsushi Nemoto <anemo at mba.ocn.ne.jp>
---
This is broken-out patch from "[PATCH RESEND] mtdpart: Avoid
divide-by-zero on out-of-reach path" on Sat, 14 Jun 2008 23:45:40
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 07c7011..a7a82c7 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -452,7 +452,9 @@ int add_mtd_partitions(struct mtd_info *master,
for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
;
- for (i--; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
+ i--;
+ slave->mtd.erasesize = regions[i].erasesize;
+ for (; i < master->numeraseregions && slave->offset + slave->mtd.size > regions[i].offset; i++) {
if (slave->mtd.erasesize < regions[i].erasesize) {
slave->mtd.erasesize = regions[i].erasesize;
}
More information about the linux-mtd
mailing list