diff options
author | Edward O'Callaghan <quasisec@google.com> | 2022-06-15 11:00:33 +1000 |
---|---|---|
committer | Julius Werner <jwerner@chromium.org> | 2022-06-16 20:38:53 +0000 |
commit | 01dbba5e3dd8ad5c3258157784291461862b9c01 (patch) | |
tree | 1404e4efbddb1b9bd9525908b6008953310ffe18 /util | |
parent | 774dcffc369989b70595e27dc96ee191bd48e34f (diff) |
util/cbfstool/common.c: Deduplicate buffer_create() logic
BUG=b:207808292,b:231152447
TEST=builds with vboot_ref uprev.
Change-Id: Id7d9b6f5254b08720eebb37151e12ee68ed7f8d7
Signed-off-by: Edward O'Callaghan <quasisec@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/65145
Reviewed-by: Julius Werner <jwerner@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'util')
-rw-r--r-- | util/cbfstool/common.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/util/cbfstool/common.c b/util/cbfstool/common.c index ea22bd6460..8ae9120acc 100644 --- a/util/cbfstool/common.c +++ b/util/cbfstool/common.c @@ -46,17 +46,17 @@ int buffer_from_file_aligned_size(struct buffer *buffer, const char *filename, perror(filename); return -1; } - buffer->offset = 0; off_t file_size = get_file_size(fp); if (file_size < 0) { fprintf(stderr, "could not determine size of %s\n", filename); fclose(fp); return -1; } - buffer->size = ALIGN_UP(file_size, size_granularity); - buffer->name = strdup(filename); - buffer->data = (char *)malloc(buffer->size); - assert(buffer->data); + if (buffer_create(buffer, ALIGN_UP(file_size, size_granularity), filename)) { + fprintf(stderr, "could not allocate buffer\n"); + fclose(fp); + return -1; + } if (fread(buffer->data, 1, file_size, fp) != (size_t)file_size) { fprintf(stderr, "incomplete read: %s\n", filename); fclose(fp); |