Attention is currently required from: Aaron Durbin. Hello Aaron Durbin,
I'd like you to do a code review. Please visit
https://review.coreboot.org/c/coreboot/+/52200
to review the following change.
Change subject: cbfs: mcache: Fix size calculation for perfectly full cache ......................................................................
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 --- M src/commonlib/bsd/cbfs_mcache.c 1 file changed, 2 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/00/52200/1
diff --git a/src/commonlib/bsd/cbfs_mcache.c b/src/commonlib/bsd/cbfs_mcache.c index 0d5d8e0..965f9fa 100644 --- a/src/commonlib/bsd/cbfs_mcache.c +++ b/src/commonlib/bsd/cbfs_mcache.c @@ -118,7 +118,7 @@ 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 @@ 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) {