
This function returns 1 on error (at least in some cases). Change it to use an error code, so that more information can be provided. For now it mostly returns either 0 or -ENOPKG Rename the return arguments, dropping the rd_ prefix and adding a 'p' (for pointer) suffix to return arguments so that is clear that this is what they are. Update the comments for clarity and to fit with the usual style. Avoid documenting the return arguments in two places. Provide a common path for all error returns. Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/image-board.c | 47 +++++++++++++++++++++++----------------------- include/image.h | 25 ++++++++++-------------- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/boot/image-board.c b/boot/image-board.c index 8e6b2974dcf..9ce996ff9a4 100644 --- a/boot/image-board.c +++ b/boot/image-board.c @@ -463,12 +463,13 @@ static int select_ramdisk(struct bootm_headers *images, const char *select, u8 a } int boot_get_ramdisk(char const *select, struct bootm_headers *images, - uint arch, ulong *rd_start, ulong *rd_end) + uint arch, ulong *startp, ulong *endp) { ulong rd_data, rd_len; + int ret; - *rd_start = 0; - *rd_end = 0; + *startp = 0; + *endp = 0; /* * Look for a '-' which indicates to ignore the @@ -476,16 +477,11 @@ int boot_get_ramdisk(char const *select, struct bootm_headers *images, */ if (select && strcmp(select, "-") == 0) { debug("## Skipping init Ramdisk\n"); - rd_len = 0; - rd_data = 0; + return -ENOPKG; } else if (select || genimg_has_config(images)) { - int ret; - ret = select_ramdisk(images, select, arch, &rd_data, &rd_len); - if (ret == -ENOPKG) - return 0; - else if (ret) - return ret; + if (ret) + goto err; } else if (images->legacy_hdr_valid && image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) { @@ -498,25 +494,28 @@ int boot_get_ramdisk(char const *select, struct bootm_headers *images, (ulong)images->legacy_hdr_os); image_multi_getimg(images->legacy_hdr_os, 1, &rd_data, &rd_len); + if (!rd_data || !rd_len) { + ret = -ENOPKG; + goto err; + } } else { - /* - * no initrd image - */ - bootstage_mark(BOOTSTAGE_ID_NO_RAMDISK); - rd_len = 0; - rd_data = 0; + /* no initrd image */ + ret = -ENOPKG; + goto err; } - if (!rd_data) { - debug("## No init Ramdisk\n"); - } else { - *rd_start = rd_data; - *rd_end = rd_data + rd_len; - } + *startp = rd_data; + *endp = rd_data + rd_len; debug(" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n", - *rd_start, *rd_end); + *startp, *endp); return 0; + +err: + bootstage_mark(BOOTSTAGE_ID_NO_RAMDISK); + debug("## No init Ramdisk\n"); + + return ret; } /** diff --git a/include/image.h b/include/image.h index 0c5575adbbf..1dba7387d5a 100644 --- a/include/image.h +++ b/include/image.h @@ -733,27 +733,22 @@ int boot_get_fpga(struct bootm_headers *images); /** * boot_get_ramdisk() - Locate the ramdisk * + * Finds a valid ramdisk image if possible, from these ramdisk sources: + * - multicomponent kernel/ramdisk image + * - commandline-provided address of dedicated ramdisk image + * * @select: address or name of ramdisk to use, or NULL for default * @images: pointer to the bootm images structure * @arch: expected ramdisk architecture - * @rd_start: pointer to a ulong variable, will hold ramdisk start address - * @rd_end: pointer to a ulong variable, will hold ramdisk end - * - * boot_get_ramdisk() is responsible for finding a valid ramdisk image. - * Currently supported are the following ramdisk sources: - * - multicomponent kernel/ramdisk image, - * - commandline provided address of decicated ramdisk image. - * - * returns: - * 0, if ramdisk image was found and valid, or skiped - * rd_start and rd_end are set to ramdisk start/end addresses if - * ramdisk image is found and valid + * @startp: returns ramdisk start address, or 0 if none + * @endp: returns ramdisk end on success, or 0 if none * - * 1, if ramdisk image is found but corrupted, or invalid - * rd_start and rd_end are set to 0 if no ramdisk exists + * Return: 0 if ramdisk image was found and valid, or skipped; + * -ENOPKG if ramdisk image is found but corrupted, or invalid; + * other error code on other error */ int boot_get_ramdisk(char const *select, struct bootm_headers *images, - uint arch, ulong *rd_start, ulong *rd_end); + uint arch, ulong *startp, ulong *endp); /** * boot_get_loadable() - load a list of binaries to memory -- 2.43.0