mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/2] bootm: always put a copy into data->of_root_node
Date: Thu, 21 Sep 2023 13:04:56 +0200	[thread overview]
Message-ID: <20230921110457.3848170-1-s.hauer@pengutronix.de> (raw)

Never put of_get_root_node() directly into data->of_root_node, but
always a copy. With this we can unconditionally free data->of_root_node
in the cleanup path.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/bootm.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/common/bootm.c b/common/bootm.c
index 9ec4b127f8..27ada61f4e 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -404,10 +404,13 @@ void *bootm_get_devicetree(struct image_data *data)
 		}
 
 	} else {
-		data->of_root_node = of_get_root_node();
-		if (!data->of_root_node)
+		struct device_node *root = of_get_root_node();
+
+		if (!root)
 			return NULL;
 
+		data->of_root_node = of_dup(root);
+
 		if (bootm_verbose(data) > 1 && data->of_root_node)
 			printf("using internal devicetree\n");
 	}
@@ -838,7 +841,7 @@ int bootm_boot(struct bootm_data *bootm_data)
 		elf_close(data->elf);
 	if (IS_ENABLED(CONFIG_FITIMAGE) && data->os_fit)
 		fit_close(data->os_fit);
-	if (data->of_root_node && data->of_root_node != of_get_root_node())
+	if (data->of_root_node)
 		of_delete_node(data->of_root_node);
 
 	globalvar_remove("linux.bootargs.bootm.earlycon");
-- 
2.39.2




             reply	other threads:[~2023-09-21 11:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-21 11:04 Sascha Hauer [this message]
2023-09-21 11:04 ` [PATCH 2/2] bootm: fix printing kernel command line Sascha Hauer

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=20230921110457.3848170-1-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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