of/fdt: Check dtb pointer first in unflatten_device_tree
PATCH 1/1 of/fdt: Check dtb pointer first in unflatten_device_tree
The setup_arch() would invoke unflatten_device_tree() even no valid fdt found. So we'd better check it first and return early.
--- drivers/of/fdt.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/of/fdt.c +5 -0
@@ -1225,6 +1225,11 @@ bool __init early_init_dt_scan(void *params)*/ void __init unflatten_device_tree (void ) { +if (!initial_boot_params) { +pr_warn ("No valid device tree found, continuing without\n" ); +return ; + } +__unflatten_device_tree (initial_boot_params,NULL , &of_root, early_init_dt_alloc_memory_arch, false);
Signature · 1 line
2.30.2
Quoted 14 lines · Changbin Du
The
setup_arch()would invokeunflatten_device_tree()even no valid fdt found. So we'd better check it first and return early.Signed-off-by Changbin Du <[email protected]>--- drivers/of/fdt.c | 5 +++++ 1 file changed, 5 insertions(+)drivers/of/fdt.c +0
-0
drivers/of/fdt.c bool __init early_init_dt_scan(void *params) · line 1229
Quoted 5 lines
drivers/of/fdt.c +2
-0@@ -1225,6 +1225,11 @@ bool __init early_init_dt_scan(void *params)*/ void __init unflatten_device_tree (void ) { +if (!initial_boot_params) { +pr_warn ("No valid device tree found, continuing without\n" );
How are you going to see this message if you have no DT?
drivers/of/fdt.c bool __init early_init_dt_scan(void *params) · line 1230
Quoted 1 line
drivers/of/fdt.c +1
-0+return ;
And the arch is supposed to just continue on oblivious that it has no DT?
drivers/of/fdt.c bool __init early_init_dt_scan(void *params) · line 1234
Quoted 4 lines
drivers/of/fdt.c +2
-0+ } +__unflatten_device_tree (initial_boot_params,NULL , &of_root, early_init_dt_alloc_memory_arch, false);
Soon as you get here with a NULL initial_boot_params, you'll get a backtrace and halt.
Quoted 4 lines
drivers/of/fdt.c +0
-1--2.30.2
Quoted 10 lines · Rob Herring
Quoted 9 lines · Changbin Du
The
setup_arch()would invokeunflatten_device_tree()even no valid fdt found. So we'd better check it first and return early.Signed-off-by Changbin Du <[email protected]>--- drivers/of/fdt.c | 5 +++++ 1 file changed, 5 insertions(+)
Quoted 13 lines
drivers/of/fdt.c bool __init early_init_dt_scan(void *params) · line 1229
Quoted 10 lines
drivers/of/fdt.c +2
-0@@ -1225,6 +1225,11 @@ bool __init early_init_dt_scan(void *params)*/ void __init unflatten_device_tree (void ) { +if (!initial_boot_params) { +pr_warn ("No valid device tree found, continuing without\n" );How are you going to see this message if you have no DT?
This aligns to what unflatten_and_copy_device_tree() does.
Quoted 4 lines
drivers/of/fdt.c bool __init early_init_dt_scan(void *params) · line 1230
Quoted 1 line
drivers/of/fdt.c +1
-0+return ;And the arch is supposed to just continue on oblivious that it has no DT?
As checking the arch code(arm, riscv), I suppose so.
Quoted 8 lines
drivers/of/fdt.c bool __init early_init_dt_scan(void *params) · line 1234
Quoted 4 lines
drivers/of/fdt.c +2
-0+ } +__unflatten_device_tree (initial_boot_params,NULL , &of_root, early_init_dt_alloc_memory_arch, false);Soon as you get here with a NULL
initial_boot_params, you'll get a backtrace and halt.
No, we have returned before.
Quoted 4 lines
Quoted 4 lines
drivers/of/fdt.c +0
-1--2.30.2
Signature · 2 lines
Cheers, Changbin Du
Quoted 25 lines · Changbin Du
Quoted 10 lines · Rob Herring
Quoted 9 lines · Changbin Du
The
setup_arch()would invokeunflatten_device_tree()even no valid fdt found. So we'd better check it first and return early.Signed-off-by Changbin Du <[email protected]>--- drivers/of/fdt.c | 5 +++++ 1 file changed, 5 insertions(+)Quoted 13 lines
drivers/of/fdt.c bool __init early_init_dt_scan(void *params) · line 1229
Quoted 10 lines
drivers/of/fdt.c +2
-0@@ -1225,6 +1225,11 @@ bool __init early_init_dt_scan(void *params)*/ void __init unflatten_device_tree (void ) { +if (!initial_boot_params) { +pr_warn ("No valid device tree found, continuing without\n" );How are you going to see this message if you have no DT?
Quoted 1 line
This aligns to what
unflatten_and_copy_device_tree()does.
Humm, then we should have a single check that covers both cases. Or we should remove that one.
Quoted 12 lines
Quoted 5 lines
drivers/of/fdt.c bool __init early_init_dt_scan(void *params) · line 1230
Quoted 2 lines
drivers/of/fdt.c +1
-0+return ;And the arch is supposed to just continue on oblivious that it has no DT?
As checking the arch
code(arm, riscv), I suppose so.Quoted 5 lines
Quoted 4 lines
drivers/of/fdt.c +2
-0+ } +__unflatten_device_tree (initial_boot_params,NULL , &of_root, early_init_dt_alloc_memory_arch, false);
Quoted 4 lines
Quoted 3 lines
Soon as you get here with a NULL
initial_boot_params, you'll get a backtrace and halt.No, we have returned before.
I mean without your addition we'll get here with a NULL.
Rob