lib/cbfs: Call rdev_unmap on hash mismatch

We don't want to leak any mappings.

BUG=b:179699789
TEST=none

Signed-off-by: Raul E Rangel <rrangel@chromium.org>
Change-Id: Ibcd28ce12cbd5e221e8f4fa910fd8472bedb802f
Reviewed-on: https://review.coreboot.org/c/coreboot/+/56576
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
This commit is contained in:
Raul E Rangel 2021-07-23 15:23:12 -06:00 committed by Felix Held
parent 4396358fd3
commit 3f41d3269e
1 changed files with 8 additions and 1 deletions

View File

@ -309,8 +309,15 @@ void *_cbfs_alloc(const char *name, cbfs_allocator_t allocator, void *arg,
loc = allocator(arg, size, &mdata);
} else if (compression == CBFS_COMPRESS_NONE) {
void *mapping = rdev_mmap_full(&rdev);
if (!mapping || cbfs_file_hash_mismatch(mapping, size, file_hash))
if (!mapping)
return NULL;
if (cbfs_file_hash_mismatch(mapping, size, file_hash)) {
rdev_munmap(&rdev, mapping);
return NULL;
}
return mapping;
} else if (!CBFS_CACHE_AVAILABLE) {
ERROR("Cannot map compressed file %s on x86\n", mdata.h.filename);