libpayload/cbfs: Fill size_out even if cbfs_map() fails

When cbfs_map()/cbfs_ro_map() fails, the caller may still want to know
the decompressed size of the CBFS file, for example, to print an error
message. Move the assignment earlier in the flow. Note that coreboot's
cbfs_map() is already doing the same.

BUG=none
TEST=emerge-geralt libpayload
BRANCH=none

Change-Id: I82c6b7e69c95bf597fa3c7d37dd11252893c01af
Signed-off-by: Yu-Ping Wu <yupingso@chromium.org>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/77193
Reviewed-by: Julius Werner <jwerner@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Yu-Ping Wu 2023-08-16 09:54:24 +08:00 committed by Matt DeVillier
parent ba7ab73900
commit 3596a5ee67
1 changed files with 7 additions and 3 deletions

View File

@ -151,6 +151,7 @@ static void *do_load(union cbfs_mdata *mdata, ssize_t offset, void *buf, size_t
bool skip_verification)
{
bool malloced = false;
size_t buf_size = 0;
size_t out_size;
uint32_t compression = CBFS_COMPRESS_NONE;
const struct cbfs_file_attr_compression *cattr =
@ -162,8 +163,13 @@ static void *do_load(union cbfs_mdata *mdata, ssize_t offset, void *buf, size_t
out_size = be32toh(mdata->h.len);
}
if (size_inout) {
buf_size = *size_inout;
*size_inout = out_size;
}
if (buf) {
if (!size_inout || *size_inout < out_size) {
if (!size_inout || buf_size < out_size) {
ERROR("'%s' buffer too small\n", mdata->h.filename);
return NULL;
}
@ -183,8 +189,6 @@ static void *do_load(union cbfs_mdata *mdata, ssize_t offset, void *buf, size_t
free(buf);
return NULL;
}
if (size_inout)
*size_inout = out_size;
return buf;
}