From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
Barebox List <barebox@lists.infradead.org>
Cc: Alexander Shiyan <eagle.alexander923@gmail.com>
Subject: Re: [PATCH] of: never fixup internal live tree
Date: Thu, 3 Aug 2023 10:55:59 +0200 [thread overview]
Message-ID: <03573857-babb-adbe-4d8a-9b8a7e9fd506@pengutronix.de> (raw)
In-Reply-To: <20230803085134.3912884-1-s.hauer@pengutronix.de>
On 03.08.23 10:51, Sascha Hauer wrote:
> 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>
Reviewed-by: Ahmad Fatoum <a.fatoum@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)
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2023-08-03 8:57 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 [this message]
2023-08-03 10:15 ` Alexander Shiyan
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=03573857-babb-adbe-4d8a-9b8a7e9fd506@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=eagle.alexander923@gmail.com \
--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