From cf20c904302f19591069b004dd8e1f747c9cd6fc Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Thu, 28 Sep 2017 17:52:59 -0600 Subject: util/cbmem: fix feedback for 'be explicit about memory map sizes' Julius made some suggestions to fix/improve commit 46300aa2. Implement those. BUG=b:66681446 Change-Id: I6becac9ffdcc65745e88734dfb80d12b581584a1 Signed-off-by: Aaron Durbin Reviewed-on: https://review.coreboot.org/21757 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- util/cbmem/cbmem.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'util') diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c index b4f41d2072..dea2c0b11e 100644 --- a/util/cbmem/cbmem.c +++ b/util/cbmem/cbmem.c @@ -102,7 +102,7 @@ static const void *mapping_virt(const struct mapping *mapping) return v + mapping->offset; } -/* Returns 0 on success, < 0 on error. mapping is filled in. */ +/* Returns virtual address on success, NULL on error. mapping is filled in. */ static const void *map_memory(struct mapping *mapping, unsigned long long phys, size_t sz) { @@ -378,14 +378,11 @@ static int parse_cbtable(u64 address, size_t table_size) return -1; /* look at every 16 bytes */ - for (i = 0; i < req_size; i += 16) { + for (i = 0; i <= req_size - sizeof(struct lb_header); i += 16) { int ret; const struct lb_header *lbh; struct mapping table_mapping; - if (req_size - i < sizeof(struct lb_header)) - return -1; - lbh = buf + i; if (memcmp(lbh->signature, "LBIO", sizeof(lbh->signature)) || !lbh->header_bytes || -- cgit v1.2.3