From: Alexander Shiyan <eagle.alexander923@gmail.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Barebox List <barebox@lists.infradead.org>
Subject: Re: [PATCH] of: never fixup internal live tree
Date: Thu, 3 Aug 2023 13:15:13 +0300 [thread overview]
Message-ID: <CAP1tNvSTZY2LC8bOfZ-_jgQZoQaVi6CDp9cmKmF7ZmBfRcYP2w@mail.gmail.com> (raw)
In-Reply-To: <20230803085134.3912884-1-s.hauer@pengutronix.de>
Now it works as expected.
Tested-by: Alexander Shiyan <eagle.alexander923@gmail.com>
чт, 3 авг. 2023 г. в 11:51, Sascha Hauer <s.hauer@pengutronix.de>:
>
> Calling of_fix_tree() on the internal live tree has undesired side
> effects, so refrain from doing so.
>
> One of the side effects is that some parts of barebox store pointers
> to properties in the live tree which might become invalid when during
> of_fixup these properties are deleted or updated.
>
> The other is that it's unexpected that the live tree is modified
> after a dry run boot with the live tree.
>
> This changes of_get_fixed_tree() to always call of_fix_tree() on
> a copy of the device tree and not on the device tree itself. To
> emphasize this make the device tree argument to of_get_fixed_tree()
> const.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> ---
> common/oftree.c | 19 ++++++++++---------
> include/of.h | 2 +-
> 2 files changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/common/oftree.c b/common/oftree.c
> index 3e85070d11..51eebd36bd 100644
> --- a/common/oftree.c
> +++ b/common/oftree.c
> @@ -416,26 +416,27 @@ void of_fix_tree(struct device_node *node)
> * It increases the size of the tree and applies the registered
> * fixups.
> */
> -struct fdt_header *of_get_fixed_tree(struct device_node *node)
> +struct fdt_header *of_get_fixed_tree(const struct device_node *node)
> {
> struct fdt_header *fdt = NULL;
> - struct device_node *freenp = NULL;
> + struct device_node *np;
>
> if (!node) {
> node = of_get_root_node();
> if (!node)
> return NULL;
> -
> - freenp = node = of_dup(node);
> - if (!node)
> - return NULL;
> }
>
> - of_fix_tree(node);
> + np = of_dup(node);
> +
> + if (!np)
> + return NULL;
> +
> + of_fix_tree(np);
>
> - fdt = of_flatten_dtb(node);
> + fdt = of_flatten_dtb(np);
>
> - of_delete_node(freenp);
> + of_delete_node(np);
>
> return fdt;
> }
> diff --git a/include/of.h b/include/of.h
> index 92a15f5c4a..0deb327971 100644
> --- a/include/of.h
> +++ b/include/of.h
> @@ -75,7 +75,7 @@ int of_add_initrd(struct device_node *root, resource_size_t start,
>
> struct fdt_header *fdt_get_tree(void);
>
> -struct fdt_header *of_get_fixed_tree(struct device_node *node);
> +struct fdt_header *of_get_fixed_tree(const struct device_node *node);
>
> /* Helper to read a big number; size is in cells (not bytes) */
> static inline u64 of_read_number(const __be32 *cell, int size)
> --
> 2.39.2
>
next prev parent reply other threads:[~2023-08-03 10:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-03 8:51 Sascha Hauer
2023-08-03 8:55 ` Ahmad Fatoum
2023-08-03 10:15 ` Alexander Shiyan [this message]
2023-08-03 10:30 ` Ahmad Fatoum
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAP1tNvSTZY2LC8bOfZ-_jgQZoQaVi6CDp9cmKmF7ZmBfRcYP2w@mail.gmail.com \
--to=eagle.alexander923@gmail.com \
--cc=barebox@lists.infradead.org \
--cc=s.hauer@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox