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>
This commit is contained in:
parent
d70d1d11ba
commit
b571846ea4
|
@ -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);
|
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;
|
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 *end = mcache + mcache_size;
|
||||||
const void *current = mcache;
|
const void *current = mcache;
|
||||||
|
|
||||||
while (current + sizeof(uint32_t) < end) {
|
while (current + sizeof(uint32_t) <= end) {
|
||||||
const union mcache_entry *entry = current;
|
const union mcache_entry *entry = current;
|
||||||
|
|
||||||
if (entry->magic == MCACHE_MAGIC_FULL || entry->magic == MCACHE_MAGIC_END) {
|
if (entry->magic == MCACHE_MAGIC_FULL || entry->magic == MCACHE_MAGIC_END) {
|
||||||
|
|
Loading…
Reference in New Issue