diff options
author | Sughosh Ganu <sughosh.ganu@linaro.org> | 2025-06-17 16:13:45 +0530 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2025-06-25 09:50:37 -0600 |
commit | 4641419f41b347a38a07f19c809b7aab63864dd1 (patch) | |
tree | f81b01ce12d4e88dda98603b08e685f3aa0732c0 | |
parent | 7aa19c3667d1cd23417f4ec7f5cb5dab260cfbf3 (diff) |
mach-snapdragon: add a check before copying FDT to fdt_addr_r
The board_late_init() function allocates memory for a bunch of
environment variables, including fdt_addr_r. The device-tree then gets
copied to the memory pointed to by fdt_addr_r. However, the memory
allocation request can fail, in which case the address that is being
written to would not be allocated. Add a check that the memory
allocation has succeeded before copying the device-tree.
Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
-rw-r--r-- | arch/arm/mach-snapdragon/board.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/arch/arm/mach-snapdragon/board.c b/arch/arm/mach-snapdragon/board.c index 87a173e0acb..ed2bd5dbade 100644 --- a/arch/arm/mach-snapdragon/board.c +++ b/arch/arm/mach-snapdragon/board.c @@ -497,7 +497,7 @@ void __weak qcom_late_init(void) /* Stolen from arch/arm/mach-apple/board.c */ int board_late_init(void) { - u32 status = 0; + u32 status = 0, fdt_status = 0; phys_addr_t addr; struct fdt_header *fdt_blob = (struct fdt_header *)gd->fdt_blob; @@ -520,14 +520,19 @@ int board_late_init(void) status |= !lmb_alloc(FASTBOOT_BUF_SIZE, &addr) ? env_set_hex("fastboot_addr_r", addr) : 1; - status |= !lmb_alloc(SZ_2M, &addr) ? + fdt_status |= !lmb_alloc(SZ_2M, &addr) ? env_set_hex("fdt_addr_r", addr) : 1; - if (status) + if (status || fdt_status) log_warning("%s: Failed to set run time variables\n", __func__); /* By default copy U-Boots FDT, it will be used as a fallback */ - memcpy((void *)addr, (void *)gd->fdt_blob, fdt32_to_cpu(fdt_blob->totalsize)); + if (fdt_status) + log_warning("%s: Failed to reserve memory for copying FDT\n", + __func__); + else + memcpy((void *)addr, (void *)gd->fdt_blob, + fdt32_to_cpu(fdt_blob->totalsize)); configure_env(); qcom_late_init(); |