1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-07-02 22:43:17 +02:00

Correct get_flash_region() to use inclusive upper bounds

get_flash_region() emits a struct flash_region, which uses chipoff_t for
the start and end addresses of a region. chipoff_t is defined as a valid
flash address, so it was wrong to be setting the end address to start +
len; this is clearly wrong in the case where there is a single region
because setting end to the flash size generates an address that is
beyond the end of the chip (due to zero-indexing).

This changes the one actual implementation of .get_region in ichspi.c to
use inclusive upper bounds, and corrects all callers of
get_flash_region() to treat the upper bounds as inclusive. Overall this
reduces complexity slightly by removing more downward adjustments by 1
than it needs to add upward adjustments.

TEST=on yaviks, `flashrom -V -x` prints equivalent messages about
     "x region (0xZZZZ..0xZZZZ) is readable" before and after this
     patch.

Change-Id: Ia0ca867aef33b598c2697fc264807fa5e29683ec
Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/82496
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Hsuan-ting Chen <roccochen@google.com>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
This commit is contained in:
Peter Marheine
2024-05-17 13:53:11 +10:00
parent d7e4240263
commit 140d65b4dd
3 changed files with 22 additions and 22 deletions

View File

@ -1436,7 +1436,7 @@ static void ich_get_region(const struct flashctx *flash, unsigned int addr, stru
region->read_prot = false;
region->write_prot = false;
region->start = 0;
region->end = flashrom_flash_getsize(flash);
region->end = flashrom_flash_getsize(flash) - 1;
for (ssize_t i = 0; i < nr; i++) {
uint32_t base = fd_regions[i].base;
@ -1459,7 +1459,7 @@ static void ich_get_region(const struct flashctx *flash, unsigned int addr, stru
/* fd_regions[i] contains addr, copy to *region. */
name = fd_regions[i].name;
region->start = base;
region->end = limit + 1;
region->end = limit;
region->read_prot = (level == LOCKED) || (level == READ_PROT);
region->write_prot = (level == LOCKED) || (level == WRITE_PROT);
break;