From patchwork Fri Sep 18 19:51:50 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [11/13] mtd: prevent a read from regions[-1] From: Andrew Morton X-Patchwork-Id: 33883 Message-Id: <200909181951.n8IJpoOq023834@imap1.linux-foundation.org> To: dwmw2@infradead.org Cc: roel.kluin@gmail.com, akpm@linux-foundation.org, linux-mtd@lists.infradead.org Date: Fri, 18 Sep 2009 12:51:50 -0700 From: Roel Kluin If the erase region was found in the first iteration we read from regions[-1] Signed-off-by: Roel Kluin Cc: David Woodhouse Signed-off-by: Andrew Morton --- drivers/mtd/mtdpart.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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++) {