Using an abuf for this function simplifies returning the size and also makes it easier to free memory afterwards. Update the API and callers.
Signed-off-by: Simon Glass <s...@chromium.org> --- boot/bootmeth-uclass.c | 12 ++++-------- boot/bootmeth_script.c | 6 ++++-- cmd/bootflow.c | 2 +- include/bootflow.h | 2 +- include/bootmeth.h | 5 ++--- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c index 78a3671f96a..02bbe77b563 100644 --- a/boot/bootmeth-uclass.c +++ b/boot/bootmeth-uclass.c @@ -360,13 +360,11 @@ int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align, } int bootmeth_alloc_other(struct bootflow *bflow, const char *fname, - enum bootflow_img_t type, void **bufp, uint *sizep) + enum bootflow_img_t type, struct abuf *buf) { struct blk_desc *desc = NULL; - struct abuf buf; char path[200]; loff_t size; - size_t bsize; int ret; snprintf(path, sizeof(path), "%s%s", bflow->subdir, fname); @@ -386,16 +384,14 @@ int bootmeth_alloc_other(struct bootflow *bflow, const char *fname, if (ret) return log_msg_ret("fs", ret); - ret = fs_read_alloc(path, size, 0, &buf); + ret = fs_read_alloc(path, size, 0, buf); if (ret) return log_msg_ret("all", ret); - if (!bootflow_img_add(bflow, bflow->fname, type, abuf_addr(&buf), size)) + if (!bootflow_img_add(bflow, bflow->fname, type, map_to_sysmem(buf), + size)) return log_msg_ret("boi", -ENOMEM); - *bufp = abuf_uninit_move(&buf, &bsize); - *sizep = bsize; - return 0; } diff --git a/boot/bootmeth_script.c b/boot/bootmeth_script.c index 020cb8a7aec..b3a51a35e89 100644 --- a/boot/bootmeth_script.c +++ b/boot/bootmeth_script.c @@ -8,6 +8,7 @@ #define LOG_CATEGORY UCLASS_BOOTSTD +#include <abuf.h> #include <blk.h> #include <bootflow.h> #include <bootmeth.h> @@ -68,6 +69,7 @@ static int script_read_bootflow_file(struct udevice *bootstd, struct blk_desc *desc = NULL; const char *const *prefixes; const char *prefix; + struct abuf buf; int ret, i; ret = uclass_first_device_err(UCLASS_BOOTSTD, &bootstd); @@ -107,8 +109,8 @@ static int script_read_bootflow_file(struct udevice *bootstd, if (ret) return log_msg_ret("inf", ret); - ret = bootmeth_alloc_other(bflow, "boot.bmp", BFI_LOGO, - &bflow->logo, &bflow->logo_size); + ret = bootmeth_alloc_other(bflow, "boot.bmp", BFI_LOGO, &buf); + bflow->logo = abuf_uninit_move(&buf, &bflow->logo_size); /* ignore error */ return 0; diff --git a/cmd/bootflow.c b/cmd/bootflow.c index e9ac9746104..0163129deba 100644 --- a/cmd/bootflow.c +++ b/cmd/bootflow.c @@ -419,7 +419,7 @@ static int do_bootflow_info(struct cmd_tbl *cmdtp, int flag, int argc, printf("Logo: %s\n", bflow->logo ? simple_xtoa((ulong)map_to_sysmem(bflow->logo)) : "(none)"); if (bflow->logo) { - printf("Logo size: %x (%d bytes)\n", bflow->logo_size, + printf("Logo size: %zx (%zd bytes)\n", bflow->logo_size, bflow->logo_size); } printf("FDT: %s\n", bflow->fdt_fname); diff --git a/include/bootflow.h b/include/bootflow.h index 2caeb80b878..d988bc9355b 100644 --- a/include/bootflow.h +++ b/include/bootflow.h @@ -101,7 +101,7 @@ struct bootflow { char *subdir; char *fname; void *logo; - uint logo_size; + size_t logo_size; char *buf; int size; int err; diff --git a/include/bootmeth.h b/include/bootmeth.h index 03301c90580..c32bbbab7e9 100644 --- a/include/bootmeth.h +++ b/include/bootmeth.h @@ -385,12 +385,11 @@ int bootmeth_alloc_file(struct bootflow *bflow, uint size_limit, uint align, * @bflow: Information about file to read * @fname: Filename to read from (within bootflow->subdir) * @type: File type (IH_TYPE_...) - * @bufp: Returns a pointer to the allocated buffer - * @sizep: Returns the size of the buffer + * @buf: Returns the allocated buffer * Return: 0 if OK, -ENOMEM if out of memory, other -ve on other error */ int bootmeth_alloc_other(struct bootflow *bflow, const char *fname, - enum bootflow_img_t type, void **bufp, uint *sizep); + enum bootflow_img_t type, struct abuf *buf); /** * bootmeth_common_read_file() - Common handler for reading a file -- 2.43.0