[PATCH RFC] fdt.c: fdt chosen cmd had off-by-one issue
Simon Glass
sjg at chromium.org
Mon Apr 7 12:49:14 CEST 2025
On Mon, 7 Apr 2025 at 18:44, George Chan via B4 Relay
<devnull+gchan9527.gmail.com at kernel.org> wrote:
>
> From: George Chan <gchan9527 at gmail.com>
>
> The kernel searching bootconfig will be off-by-1 and never match
> thus always not found in this case.
>
> Signed-off-by: George Chan <gchan9527 at gmail.com>
> ---
> The searching will shift-by-1 and never match the bootconfig thus
> always not found bootconfig this case.
>
> Kernel:
> data = (char *)initrd_end - BOOTCONFIG_MAGIC_LEN;
> for (i = 0; i < 4; i++) {
> if (!memcmp(data, BOOTCONFIG_MAGIC, BOOTCONFIG_MAGIC_LEN))
> goto found;
> data--;
> }
> u-boot:
> initrd_end = initrd_start + hextoul(argv[3], NULL) - 1;
>
> That would be off-by-one apprently and matching fail for bootconfig.
> Both u-boot and kernel worth a fix.
>
> An out-of-tree patch for kernel to relax the searching is available
> but not ready for submit.
> https://github.com/99degree/linux/commit/9d9ea454fe857a9f550d7e60957253e176e8e123
> ---
> cmd/fdt.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/cmd/fdt.c b/cmd/fdt.c
> index d16b141ce32..13ffe929f8b 100644
> --- a/cmd/fdt.c
> +++ b/cmd/fdt.c
> @@ -705,7 +705,7 @@ static int do_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
>
> if (argc == 4) {
> initrd_start = hextoul(argv[2], NULL);
> - initrd_end = initrd_start + hextoul(argv[3], NULL) - 1;
> + initrd_end = initrd_start + hextoul(argv[3], NULL);
> }
>
> fdt_chosen(working_fdt);
>
> ---
> base-commit: 848f7ffc64aa7c4cc2229095812625c12343c8c1
> change-id: 20250407-fdt-chosen-c87045f2e1e9
>
> Best regards,
> --
> George Chan <gchan9527 at gmail.com>
>
>
Reviewed-by: Simon Glass <sjg at chromium.org>
More information about the U-Boot
mailing list