mirror of
https://review.coreboot.org/flashrom.git
synced 2025-07-03 06:53:18 +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:
@ -318,13 +318,13 @@ int erase_write(struct flashctx *const flashctx, chipoff_t region_start, chipoff
|
||||
struct flash_region region;
|
||||
get_flash_region(flashctx, addr, ®ion);
|
||||
|
||||
len = min(start_addr + block_len, region.end) - addr;
|
||||
len = min(start_addr + block_len, region.end + 1) - addr;
|
||||
|
||||
if (region.write_prot) {
|
||||
msg_gdbg("%s: cannot erase inside %s "
|
||||
"region (%#08"PRIx32"..%#08"PRIx32"), skipping range (%#08x..%#08x).\n",
|
||||
__func__, region.name,
|
||||
region.start, region.end - 1,
|
||||
region.start, region.end,
|
||||
addr, addr + len - 1);
|
||||
free(region.name);
|
||||
continue;
|
||||
@ -333,7 +333,7 @@ int erase_write(struct flashctx *const flashctx, chipoff_t region_start, chipoff
|
||||
msg_gdbg("%s: %s region (%#08"PRIx32"..%#08"PRIx32") is "
|
||||
"writable, erasing range (%#08x..%#08x).\n",
|
||||
__func__, region.name,
|
||||
region.start, region.end - 1,
|
||||
region.start, region.end,
|
||||
addr, addr + len - 1);
|
||||
free(region.name);
|
||||
|
||||
|
Reference in New Issue
Block a user