Patchwork MTD: Prevent a read from regions[-1]

login
register
mail settings
Submitter roel kluin
Date Aug. 9, 2009, 9:38 a.m.
Message ID <4A7E9917.4050307@gmail.com>
Download mbox | patch
Permalink /patch/31014/
State New
Headers show

Comments

roel kluin - Aug. 9, 2009, 9:38 a.m.
If the erase region was found in the first iteration we read from
regions[-1]

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---

Patch

diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 349fcbe..a83cfa1 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -453,7 +453,8 @@  static struct mtd_part *add_one_partition(struct mtd_info *master,
 		for (i = 0; i < max && regions[i].offset <= slave->offset; i++)
 			;
 		/* The loop searched for the region _behind_ the first one */
-		i--;
+		if (i > 0)
+			i--;
 
 		/* Pick biggest erasesize */
 		for (; i < max && regions[i].offset < end; i++) {