mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Stefan Kerkmann <s.kerkmann@pengutronix.de>
To: Sascha Hauer <s.hauer@pengutronix.de>,
	 "open list:BAREBOX" <barebox@lists.infradead.org>
Cc: Stefan Kerkmann <s.kerkmann@pengutronix.de>
Subject: [PATCH v2 1/5] of: overlay: of_overlay_fix_path: skip symbols without __overlay__ node
Date: Mon, 19 Oct 2026 12:05:44 +0200	[thread overview]
Message-ID: <20261019-fix-overlay-v2-1-24e9ff1c0e12@pengutronix.de> (raw)
In-Reply-To: <20261019-fix-overlay-v2-0-24e9ff1c0e12@pengutronix.de>

An overlay with a label entry in the `__symbols__` table without a
matching fragment that contains an `__overlay__` is not an error. This
matches the behavior of the dtc libfdt implementation[1].

This edge case was triggered by:

1. Enabling CONFIG_OF_OVERLAY_LIVE this adds a `__symbols__` table to
   device trees compiled by barebox.

2. Passing the barebox devicetree via TF-A to OP-TEE that adds overlay
   fragments to the barebox device tree.

3. Enabling CONFIG_OPTEE_APPLY_OVERLAY and applying the same DT again as
   a DT overlay. The DT in this case was expanded by OP-TEE with overlay
   fragments (and still contains the __symbol__ table with entries that
   do not reference the OP-TEE fragments).

[1]: 5c715a4 ("fdtoverlay: Ignore symbols in overlays which don't apply to the target tree")

Fixes: 6553d2c2a5e3 ("of: overlay: avoid potential null pointer exception")
Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
---
 drivers/of/overlay.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index 4ce45513ea..a1df9c3c79 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -99,27 +99,37 @@ static int of_overlay_apply(struct device_node *target,
 static char *of_overlay_fix_path(struct device_node *root,
 				 struct device_node *overlay, const char *path)
 {
+	struct device_node *overlay_node;
 	struct device_node *fragment;
 	struct device_node *target;
 	const char *path_tail;
 	const char *prefix;
+	size_t prefix_len;
 
 	fragment = of_find_node_by_path_from(overlay, path);
 	while ((fragment = of_get_parent(fragment)) != NULL) {
-		if (of_get_child_by_name(fragment, "__overlay__"))
+		overlay_node = of_get_child_by_name(fragment, "__overlay__");
+		if (overlay_node != NULL)
 			break;
 	}
+
 	if (!fragment) {
-		pr_info("could not find __overlay__ node\n");
+		pr_debug("could not find __overlay__ node for %s\n", path);
+		return NULL;
+	}
+
+	prefix = overlay_node->full_name;
+	prefix_len = str_has_prefix(path, prefix);
+	if (!prefix_len || !strchr("/", path[prefix_len])) {
+		pr_debug("%s is not below %pOF\n", path, overlay_node);
 		return NULL;
 	}
 
 	target = find_target(root, fragment, false);
 	if (!target)
-		return NULL;
+		return ERR_PTR(-EINVAL);
 
-	prefix = of_get_child_by_name(fragment, "__overlay__")->full_name;
-	path_tail = path + strlen(prefix);
+	path_tail = path + prefix_len;
 
 	return basprintf("%pOF%s", target, path_tail);
 }
@@ -152,8 +162,10 @@ static int of_overlay_apply_symbols(struct device_node *root,
 
 		old_path = of_property_get_value(prop);
 		new_path = of_overlay_fix_path(root, overlay, old_path);
+		if (IS_ERR(new_path))
+			return PTR_ERR(new_path);
 		if (!new_path)
-			return -EINVAL;
+			continue;
 
 		pr_debug("add symbol %s with new path %s\n",
 			 prop->name, new_path);

-- 
2.47.3




  reply	other threads:[~2026-10-19 10:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19 10:05 [PATCH v2 0/5] of: overlay: fix __symbols__ handling and add selftest suite Stefan Kerkmann
2026-10-19 10:05 ` Stefan Kerkmann [this message]
2026-10-19 10:05 ` [PATCH v2 2/5] of: overlay: fix_path/apply_symbols: add more debugging calls Stefan Kerkmann
2026-10-19 10:05 ` [PATCH v2 3/5] tests: of_overlay: add selftests skeleton Stefan Kerkmann
2026-10-19 10:05 ` [PATCH v2 4/5] tests: of_overlay: add __symbols__ merging tests Stefan Kerkmann
2026-10-19 10:05 ` [PATCH v2 5/5] tests: of_overlay: add fragment application tests Stefan Kerkmann
2026-10-20  7:14 ` [PATCH v2 0/5] of: overlay: fix __symbols__ handling and add selftest suite 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=20261019-fix-overlay-v2-1-24e9ff1c0e12@pengutronix.de \
    --to=s.kerkmann@pengutronix.de \
    --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