[PATCH] cfi_flash: fix bug with flash banks with different
Martin Krause
martin.krause at tqs.de
Mon Mar 21 13:08:19 CET 2011
sector numbers
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 at tqs.de>
---
drivers/mtd/cfi_flash.c | 5 +++++
1 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/drivers/mtd/cfi_flash.c b/drivers/mtd/cfi_flash.c
index 24eb33f..ff1457c 100644
--- a/drivers/mtd/cfi_flash.c
+++ b/drivers/mtd/cfi_flash.c
@@ -653,8 +653,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 =3D 0; /* previously found =
sector
*/
+ static flash_info_t *saved_info =3D 0; /* previously used flash
bank */
flash_sect_t sector =3D saved_sector;
+ if ((info !=3D saved_info) || (sector >=3D info->sector_count))
+ sector =3D 0;
+
while ((info->start[sector] < addr)
&& (sector < info->sector_count - 1))
sector++;
@@ -666,6 +670,7 @@ static flash_sect_t find_sector (flash_info_t *
info, ulong addr)
sector--;
saved_sector =3D sector;
+ saved_info =3D info;
return sector;
}
--
1.6.6.1
More information about the U-Boot
mailing list