linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] of/fdt: Check dtb pointer first in unflatten_device_tree
@ 2021-03-24 15:04 Changbin Du
  2021-03-24 16:52 ` Rob Herring
  0 siblings, 1 reply; 4+ messages in thread
From: Changbin Du @ 2021-03-24 15:04 UTC (permalink / raw)
  To: Rob Herring, Frank Rowand; +Cc: devicetree, linux-kernel, Changbin Du

The setup_arch() would invoke unflatten_device_tree() even no
valid fdt found. So we'd better check it first and return early.

Signed-off-by: Changbin Du <changbin.du@gmail.com>
---
 drivers/of/fdt.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
index dcc1dd96911a..05d439d63bc5 100644
--- a/drivers/of/fdt.c
+++ b/drivers/of/fdt.c
@@ -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);
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] of/fdt: Check dtb pointer first in unflatten_device_tree
  2021-03-24 15:04 [PATCH] of/fdt: Check dtb pointer first in unflatten_device_tree Changbin Du
@ 2021-03-24 16:52 ` Rob Herring
  2021-03-25 16:00   ` Changbin Du
  0 siblings, 1 reply; 4+ messages in thread
From: Rob Herring @ 2021-03-24 16:52 UTC (permalink / raw)
  To: Changbin Du; +Cc: Frank Rowand, devicetree, linux-kernel

On Wed, Mar 24, 2021 at 9:04 AM Changbin Du <changbin.du@gmail.com> wrote:
>
> The setup_arch() would invoke unflatten_device_tree() even no
> valid fdt found. So we'd better check it first and return early.
>
> Signed-off-by: Changbin Du <changbin.du@gmail.com>
> ---
>  drivers/of/fdt.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> index dcc1dd96911a..05d439d63bc5 100644
> --- a/drivers/of/fdt.c
> +++ b/drivers/of/fdt.c
> @@ -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?

> +               return;

And the arch is supposed to just continue on oblivious that it has no DT?

> +       }
> +
>         __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.

>
> --
> 2.30.2
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] of/fdt: Check dtb pointer first in unflatten_device_tree
  2021-03-24 16:52 ` Rob Herring
@ 2021-03-25 16:00   ` Changbin Du
  2021-03-25 16:28     ` Rob Herring
  0 siblings, 1 reply; 4+ messages in thread
From: Changbin Du @ 2021-03-25 16:00 UTC (permalink / raw)
  To: Rob Herring; +Cc: Changbin Du, Frank Rowand, devicetree, linux-kernel

On Wed, Mar 24, 2021 at 10:52:30AM -0600, Rob Herring wrote:
> On Wed, Mar 24, 2021 at 9:04 AM Changbin Du <changbin.du@gmail.com> wrote:
> >
> > The setup_arch() would invoke unflatten_device_tree() even no
> > valid fdt found. So we'd better check it first and return early.
> >
> > Signed-off-by: Changbin Du <changbin.du@gmail.com>
> > ---
> >  drivers/of/fdt.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> > index dcc1dd96911a..05d439d63bc5 100644
> > --- a/drivers/of/fdt.c
> > +++ b/drivers/of/fdt.c
> > @@ -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.
 
> > +               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.

> > +       }
> > +
> >         __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.

> >
> > --
> > 2.30.2
> >

-- 
Cheers,
Changbin Du

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] of/fdt: Check dtb pointer first in unflatten_device_tree
  2021-03-25 16:00   ` Changbin Du
@ 2021-03-25 16:28     ` Rob Herring
  0 siblings, 0 replies; 4+ messages in thread
From: Rob Herring @ 2021-03-25 16:28 UTC (permalink / raw)
  To: Changbin Du; +Cc: Frank Rowand, devicetree, linux-kernel

On Thu, Mar 25, 2021 at 10:00 AM Changbin Du <changbin.du@gmail.com> wrote:
>
> On Wed, Mar 24, 2021 at 10:52:30AM -0600, Rob Herring wrote:
> > On Wed, Mar 24, 2021 at 9:04 AM Changbin Du <changbin.du@gmail.com> wrote:
> > >
> > > The setup_arch() would invoke unflatten_device_tree() even no
> > > valid fdt found. So we'd better check it first and return early.
> > >
> > > Signed-off-by: Changbin Du <changbin.du@gmail.com>
> > > ---
> > >  drivers/of/fdt.c | 5 +++++
> > >  1 file changed, 5 insertions(+)
> > >
> > > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c
> > > index dcc1dd96911a..05d439d63bc5 100644
> > > --- a/drivers/of/fdt.c
> > > +++ b/drivers/of/fdt.c
> > > @@ -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.

Humm, then we should have a single check that covers both cases. Or we
should remove that one.

>
> > > +               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.
>
> > > +       }
> > > +
> > >         __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.

I mean without your addition we'll get here with a NULL.

Rob

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-25 16:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-24 15:04 [PATCH] of/fdt: Check dtb pointer first in unflatten_device_tree Changbin Du
2021-03-24 16:52 ` Rob Herring
2021-03-25 16:00   ` Changbin Du
2021-03-25 16:28     ` Rob Herring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).