public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH RESEND] mtdpart: Avoid divide-by-zero on out-of-reach path
@ 2008-06-14 14:45 Atsushi Nemoto
  2008-06-16  8:33 ` Jörn Engel
  0 siblings, 1 reply; 8+ messages in thread
From: Atsushi Nemoto @ 2008-06-14 14:45 UTC (permalink / raw)
  To: linux-mtd; +Cc: akpm, David Woodhouse

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.

This patch also contains some cleanups.  Do not shadow symbol 'i',
fold long lines, etc.

Signed-off-by: Atsushi Nemoto <anemo@mba.ocn.ne.jp>
---
 drivers/mtd/mtdpart.c |   25 +++++++++++++++----------
 1 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 07c7011..ff9ea3a 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -445,17 +445,22 @@ int add_mtd_partitions(struct mtd_info *master,
 		}
 		if (master->numeraseregions>1) {
 			/* Deal with variable erase size stuff */
-			int i;
-			struct mtd_erase_region_info *regions = master->eraseregions;
-
-			/* Find the first erase regions which is part of this partition. */
-			for (i=0; i < master->numeraseregions && slave->offset >= regions[i].offset; i++)
+			int j, num = master->numeraseregions;
+			struct mtd_erase_region_info *r = master->eraseregions;
+			/*
+			 * Find the first erase region which is part
+			 * of this partition.
+			 */
+			for (j = 0; j < num && slave->offset >= r[j].offset;
+				j++)
 				;
-
-			for (i--; 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;
-				}
+			j--;
+			slave->mtd.erasesize = r[j].erasesize;
+			for (; j < num &&
+				slave->offset + slave->mtd.size > r[j].offset;
+				j++) {
+				if (slave->mtd.erasesize < r[j].erasesize)
+					slave->mtd.erasesize = r[j].erasesize;
 			}
 		} else {
 			/* Single erase size */

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

end of thread, other threads:[~2008-06-17 15:42 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-14 14:45 [PATCH RESEND] mtdpart: Avoid divide-by-zero on out-of-reach path Atsushi Nemoto
2008-06-16  8:33 ` Jörn Engel
2008-06-16 14:30   ` Atsushi Nemoto
2008-06-16 14:57     ` Jörn Engel
2008-06-16 15:03       ` David Woodhouse
2008-06-17 14:09         ` Atsushi Nemoto
2008-06-17 14:10           ` David Woodhouse
2008-06-17 15:44             ` Atsushi Nemoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox