diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2021-05-17 20:54:15 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-05-18 08:24:46 +0200 |
commit | 437943492cf23cc93fef413c8e112abe02396524 (patch) | |
tree | b8d1db4869122960939e739b9efa5a3ab48a4f32 | |
parent | 89846de3d35791d4b6c7bbd949ac8df2d59f0117 (diff) | |
download | barebox-437943492cf23cc93fef413c8e112abe02396524.tar.gz barebox-437943492cf23cc93fef413c8e112abe02396524.tar.xz |
mtd: cfi-flash: Fix compiler warning
sector >= 0 is always true for the unsigned type flash_sect_t. This
means the loop to find the sector will only behave correctly when we
actually find the sector, but not in the error case. The error case
is not expected though and will not happen when the code is correct,
so just catch it with a BUG().
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Link: https://lore.barebox.org/20210517185424.32145-7-s.hauer@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/mtd/nor/cfi_flash.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/mtd/nor/cfi_flash.c b/drivers/mtd/nor/cfi_flash.c index ba0bd1b4eb..ffd29d80a7 100644 --- a/drivers/mtd/nor/cfi_flash.c +++ b/drivers/mtd/nor/cfi_flash.c @@ -466,9 +466,16 @@ flash_sect_t find_sector(struct flash_info *info, unsigned long addr) { flash_sect_t sector; - for (sector = info->sector_count - 1; sector >= 0; sector--) { + sector = info->sector_count - 1; + + while (1) { if (addr >= info->start[sector]) break; + + if (sector == 0) + BUG(); + + sector--; } return sector; |