Skip to content

Commit

Permalink
of/fdt: run soc memory setup when early_init_dt_scan_memory fails
Browse files Browse the repository at this point in the history
commit 2a12187 upstream.

If memory has been found early_init_dt_scan_memory now returns 1. If
it hasn't found any memory it will return 0, allowing other memory
setup mechanisms to carry on.

Previously early_init_dt_scan_memory always returned 0 without
distinguishing between any kind of memory setup being done or not. Any
code path after the early_init_dt_scan memory call in the ramips
plat_mem_setup code wouldn't be executed anymore. Making
early_init_dt_scan_memory the only way to initialize the memory.

Some boards, including my mt7621 based Cudy X6 board, depend on memory
initialization being done via the soc_info.mem_detect function
pointer. Those wouldn't be able to obtain memory and panic the kernel
during early bootup with the message "early_init_dt_alloc_memory_arch:
Failed to allocate 12416 bytes align=0x40".

Fixes: 1f01228 ("of/fdt: Rework early_init_dt_scan_memory() to call directly")
Cc: stable@vger.kernel.org
Signed-off-by: Andreas Rammhold <andreas@rammhold.de>
Link: https://lore.kernel.org/r/20221223112748.2935235-1-andreas@rammhold.de
Signed-off-by: Rob Herring <robh@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
andir authored and gregkh committed Jan 12, 2023
1 parent a33220f commit c4849f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion arch/mips/ralink/of.c
Expand Up @@ -64,7 +64,7 @@ void __init plat_mem_setup(void)
dtb = get_fdt();
__dt_setup_arch(dtb);

if (!early_init_dt_scan_memory())
if (early_init_dt_scan_memory())
return;

if (soc_info.mem_detect)
Expand Down
6 changes: 4 additions & 2 deletions drivers/of/fdt.c
Expand Up @@ -1099,7 +1099,7 @@ u64 __init dt_mem_next_cell(int s, const __be32 **cellp)
*/
int __init early_init_dt_scan_memory(void)
{
int node;
int node, found_memory = 0;
const void *fdt = initial_boot_params;

fdt_for_each_subnode(node, fdt, 0) {
Expand Down Expand Up @@ -1139,6 +1139,8 @@ int __init early_init_dt_scan_memory(void)

early_init_dt_add_memory_arch(base, size);

found_memory = 1;

if (!hotpluggable)
continue;

Expand All @@ -1147,7 +1149,7 @@ int __init early_init_dt_scan_memory(void)
base, base + size);
}
}
return 0;
return found_memory;
}

int __init early_init_dt_scan_chosen(char *cmdline)
Expand Down

0 comments on commit c4849f1

Please sign in to comment.