Patchwork [11/13] mtd: prevent a read from regions[-1]

login
register
mail settings
Submitter Andrew Morton
Date Sept. 18, 2009, 7:51 p.m.
Message ID <200909181951.n8IJpoOq023834@imap1.linux-foundation.org>
Download mbox | patch
Permalink /patch/33883/
State New, archived
Headers show

Comments

Andrew Morton - Sept. 18, 2009, 7:51 p.m.
From: Roel Kluin <roel.kluin@gmail.com>

If the erase region was found in the first iteration we read from
regions[-1]

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Cc: David Woodhouse <dwmw2@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/mtd/mtdpart.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch

diff -puN drivers/mtd/mtdpart.c~mtd-prevent-a-read-from-regions drivers/mtd/mtdpart.c
--- a/drivers/mtd/mtdpart.c~mtd-prevent-a-read-from-regions
+++ a/drivers/mtd/mtdpart.c
@@ -453,7 +453,8 @@  static struct mtd_part *add_one_partitio
 		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++) {