diff options
author | Yu-Ping Wu <yupingso@chromium.org> | 2023-08-16 09:54:24 +0800 |
---|---|---|
committer | Matt DeVillier <matt.devillier@amd.corp-partner.google.com> | 2023-08-18 14:15:19 +0000 |
commit | 3596a5ee67b1d3e37aadbcd003d6970998985cce (patch) | |
tree | 82a7d5f20f60a016b21e0be91228a720d7730206 /payloads/libpayload/libcbfs | |
parent | ba7ab73900dc6c163e0b36a3e8a435978276d733 (diff) |
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>
Diffstat (limited to 'payloads/libpayload/libcbfs')
-rw-r--r-- | payloads/libpayload/libcbfs/cbfs.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/payloads/libpayload/libcbfs/cbfs.c b/payloads/libpayload/libcbfs/cbfs.c index a158ba8fa1..3dc19d2e7d 100644 --- a/payloads/libpayload/libcbfs/cbfs.c +++ b/payloads/libpayload/libcbfs/cbfs.c @@ -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; } |