Эх сурвалжийг харах

mtd: mtdpart: prevent a read from regions[-1]

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

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Roel Kluin 15 жил өмнө
parent
commit
a57ca0466a

+ 2 - 1
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++)
 		for (i = 0; i < max && regions[i].offset <= slave->offset; i++)
 			;
 			;
 		/* The loop searched for the region _behind_ the first one */
 		/* The loop searched for the region _behind_ the first one */
-		i--;
+		if (i > 0)
+			i--;
 
 
 		/* Pick biggest erasesize */
 		/* Pick biggest erasesize */
 		for (; i < max && regions[i].offset < end; i++) {
 		for (; i < max && regions[i].offset < end; i++) {