Ed Sharma has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/68637 )
Change subject: commonlib/fsp_relocate: Fix Coverity Issues ......................................................................
commonlib/fsp_relocate: Fix Coverity Issues
Recently committed change 1df1cf9 resulted in some Coverity reported issues. This change attempts to fix the static analysis issues reported.
TESTED= This code is tested with FSP version 33A for DeltaLake boot
Signed-off-by: Eddie Sharma aeddiesharma@fb.com Change-Id: I635c62929e8be9a474a91a62c29c3b5ee9b0ee64 --- M src/commonlib/fsp_relocate.c 1 file changed, 28 insertions(+), 6 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/37/68637/1
diff --git a/src/commonlib/fsp_relocate.c b/src/commonlib/fsp_relocate.c index 8dabad5..19eecf3 100644 --- a/src/commonlib/fsp_relocate.c +++ b/src/commonlib/fsp_relocate.c @@ -177,11 +177,12 @@ EFI_IMAGE_OPTIONAL_HEADER32 *ophdr; FSP_INFO_HEADER *fih; uint32_t roffset, rsize; - uint32_t offset; + uint32_t offset, offset_limit; uint8_t *pe_base = pe; uint32_t image_base; uint32_t img_base_off; uint32_t delta; + void *ptr = NULL;
doshdr = pe; if (read_le16(&doshdr->e_magic) != EFI_IMAGE_DOS_SIGNATURE) { @@ -226,7 +227,8 @@ // TODO - add support for PE32+ also
offset = roffset; - while (offset < (roffset + rsize)) { + offset_limit = roffset + rsize; + while (offset < offset_limit) { uint32_t vaddr; uint32_t rlen, rnum; uint16_t *rdata; @@ -253,10 +255,11 @@ case EFI_IMAGE_REL_BASED_ABSOLUTE: continue; case EFI_IMAGE_REL_BASED_HIGHLOW: - val = read_le32(&pe_base[aoff]); + ptr = &pe_base[aoff]; + val = read_le32(ptr); printk(FSP_DBG_LVL, "Adjusting %p %x -> %x\n", - &pe_base[aoff], val, val + delta); - write_le32(&pe_base[aoff], val + delta); + ptr, val, val + delta); + write_le32(ptr, val + delta); break; case EFI_IMAGE_REL_BASED_DIR64: printk(BIOS_ERR, "Error: Unsupported DIR64\n"); @@ -647,7 +650,9 @@ } else if (read_le8(&csh->Type) == EFI_SECTION_PE32) { printk(FSP_DBG_LVL, "PE32 image at offset %zx\n", section_offset); - pe_relocate(new_addr, section_data, fsp, *fih_offset); + if (fih_offset) { + pe_relocate(new_addr, section_data, fsp, *fih_offset); + } }
offset += data_size + data_offset;