]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
cfi_flash: fix bug with flash banks with different sector numbers
authorMartin Krause <martin.krause@tqs.de>
Mon, 21 Mar 2011 17:07:56 +0000 (18:07 +0100)
committerStefan Roese <sr@denx.de>
Mon, 28 Mar 2011 17:06:51 +0000 (19:06 +0200)
The function find_sector() does not take into account if the flash bank
has changed since the last call. This could lead to illegal accesses inside
and beyond the flash_info_t info strcture. For example if the current
flash bank has less sectors than the last used flash bank.

This patch adds two cheks. One that insures, that the current sector does
not exceed the allowed maximum (which is always a good idea). And one that
checks if the current access is to the same flash bank as the last access.
If not, the search loop will start with sector 0.

Signed-off-by: Martin Krause <martin.krause@tqs.de>
Signed-off-by: Stefan Roese <sr@denx.de>
drivers/mtd/cfi_flash.c

index dd394a81ffefd31ddaa127bf4d2895dae4ad3f02..0909fe715ac4a1962d742ce704f0506d3d969e20 100644 (file)
@@ -744,8 +744,12 @@ static void flash_add_byte (flash_info_t * info, cfiword_t * cword, uchar c)
 static flash_sect_t find_sector (flash_info_t * info, ulong addr)
 {
        static flash_sect_t saved_sector = 0; /* previously found sector */
+       static flash_info_t *saved_info = 0; /* previously used flash bank */
        flash_sect_t sector = saved_sector;
 
+       if ((info != saved_info) || (sector >= info->sector_count))
+               sector = 0;
+
        while ((info->start[sector] < addr)
                        && (sector < info->sector_count - 1))
                sector++;
@@ -757,6 +761,7 @@ static flash_sect_t find_sector (flash_info_t * info, ulong addr)
                sector--;
 
        saved_sector = sector;
+       saved_info = info;
        return sector;
 }