diff options
author | Julius Werner <jwerner@chromium.org> | 2021-04-08 17:08:28 -0700 |
---|---|---|
committer | Julius Werner <jwerner@chromium.org> | 2021-04-10 00:00:34 +0000 |
commit | b571846ea4e69981dc593faa82c861cdd6ece078 (patch) | |
tree | 8bc53fb6c18d661e28dc3febc4406f1ee0850cf5 /src/commonlib | |
parent | d70d1d11bafb80f054e537db88ebce2bac3cd89a (diff) |
cbfs: mcache: Fix size calculation for perfectly full cache
cbfs_mcache_real_size() has a subtle flaw: when the cache is perfectly
full to the end (so that the termination token sits exactly at the end
of the available space), the loop counting the size ends prematurely.
This means that when migrating the cache to CBMEM the terminating token
is not copied, which isn't actually noticeable unless you're looking for
a file that's not in the cache (because it doesn't exist or because not
all files fit when building).
This patch fixes the problem and slightly changes the error message for
when a cache isn't terminated (to make it more clear that this is a
different condition from a "normal" cache overflow that can happen when
building if there's not enough room to fit all files).
Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: I8d89e7dadc958f97b173b3a2352f2010c8a3d1d5
Reviewed-on: https://review.coreboot.org/c/coreboot/+/52200
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src/commonlib')
-rw-r--r-- | src/commonlib/bsd/cbfs_mcache.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/commonlib/bsd/cbfs_mcache.c b/src/commonlib/bsd/cbfs_mcache.c index 0d5d8e0221..965f9faef6 100644 --- a/src/commonlib/bsd/cbfs_mcache.c +++ b/src/commonlib/bsd/cbfs_mcache.c @@ -118,7 +118,7 @@ cb_err_t cbfs_mcache_lookup(const void *mcache, size_t mcache_size, const char * current += ALIGN_UP(data_offset, CBFS_MCACHE_ALIGNMENT); } - ERROR("CBFS mcache overflow!\n"); + ERROR("CBFS mcache is not terminated!\n"); /* should never happen */ return CB_ERR; } @@ -127,7 +127,7 @@ size_t cbfs_mcache_real_size(const void *mcache, size_t mcache_size) const void *end = mcache + mcache_size; const void *current = mcache; - while (current + sizeof(uint32_t) < end) { + while (current + sizeof(uint32_t) <= end) { const union mcache_entry *entry = current; if (entry->magic == MCACHE_MAGIC_FULL || entry->magic == MCACHE_MAGIC_END) { |