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 <adurbin@chromium.org>
Reviewed-on: https://review.coreboot.org/21757
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
This commit is contained in:
Aaron Durbin 2017-09-28 17:52:59 -06:00
parent 7c48b891fe
commit cf20c90430
1 changed files with 2 additions and 5 deletions

View File

@ -102,7 +102,7 @@ static const void *mapping_virt(const struct mapping *mapping)
return v + mapping->offset; 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, static const void *map_memory(struct mapping *mapping, unsigned long long phys,
size_t sz) size_t sz)
{ {
@ -378,14 +378,11 @@ static int parse_cbtable(u64 address, size_t table_size)
return -1; return -1;
/* look at every 16 bytes */ /* 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; int ret;
const struct lb_header *lbh; const struct lb_header *lbh;
struct mapping table_mapping; struct mapping table_mapping;
if (req_size - i < sizeof(struct lb_header))
return -1;
lbh = buf + i; lbh = buf + i;
if (memcmp(lbh->signature, "LBIO", sizeof(lbh->signature)) || if (memcmp(lbh->signature, "LBIO", sizeof(lbh->signature)) ||
!lbh->header_bytes || !lbh->header_bytes ||