cfi_mtd: Fix bug in last sector detection
authorStefan Roese <sr@denx.de>
Mon, 11 May 2009 13:54:13 +0000 (15:54 +0200)
committerWolfgang Denk <wd@denx.de>
Wed, 3 Jun 2009 21:45:27 +0000 (23:45 +0200)
This patch now enabled this cfi-mtd wrapper to correctly detect and
erase the last sector in an NOR FLASH device.

Signed-off-by: Stefan Roese <sr@denx.de>
drivers/mtd/cfi_mtd.c

index f03e4fbd728d576dc07dea34a151d86279ef5e82..4a76917ac39c35f1f8ad54662ae6b314eb19d2b2 100644 (file)
@@ -43,11 +43,16 @@ static int cfi_mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
        int s_last = -1;
        int error, sect;
 
-       for (sect = 0; sect < fi->sector_count - 1; sect++) {
+       for (sect = 0; sect < fi->sector_count; sect++) {
                if (a_start == fi->start[sect])
                        s_first = sect;
 
-               if (a_end == fi->start[sect + 1]) {
+               if (sect < fi->sector_count - 1) {
+                       if (a_end == fi->start[sect + 1]) {
+                               s_last = sect;
+                               break;
+                       }
+               } else {
                        s_last = sect;
                        break;
                }