mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH v2 0/5] of: overlay: fix __symbols__ handling and add selftest suite
@ 2026-10-19 10:05 Stefan Kerkmann
  2026-10-19 10:05 ` [PATCH v2 1/5] of: overlay: of_overlay_fix_path: skip symbols without __overlay__ node Stefan Kerkmann
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Stefan Kerkmann @ 2026-10-19 10:05 UTC (permalink / raw)
  To: Sascha Hauer, open list:BAREBOX; +Cc: Stefan Kerkmann

Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
---
Changes in v2:
- Added: selftest suite to cover of_overlay handling
- Fixed: labels (symbol) inside a fragment but not under an __overlay__
  node are ignored
- Link to v1: https://patch.msgid.link/20261014-fix-overlay-v1-0-cfd44746d985@pengutronix.de

To: Sascha Hauer <s.hauer@pengutronix.de>
To: "open list:BAREBOX" <barebox@lists.infradead.org>

---
Stefan Kerkmann (5):
      of: overlay: of_overlay_fix_path: skip symbols without __overlay__ node
      of: overlay: fix_path/apply_symbols: add more debugging calls
      tests: of_overlay: add selftests skeleton
      tests: of_overlay: add __symbols__ merging tests
      tests: of_overlay: add fragment application tests

 drivers/of/overlay.c                     |  30 ++++--
 test/self/Kconfig                        |   7 ++
 test/self/Makefile                       |   5 +
 test/self/of_overlay.c                   | 174 +++++++++++++++++++++++++++++++
 test/self/of_overlay.dtso                |  34 ++++++
 test/self/of_overlay_missing_target.dtso |  24 +++++
 test/self/of_overlay_with_symbols.dts    |  14 +++
 test/self/of_overlay_with_symbols.dtso   |  43 ++++++++
 8 files changed, 323 insertions(+), 8 deletions(-)
---
base-commit: e82842ffe3c7993dac4f8493fb4a44c4d35810ca
change-id: 20261014-fix-overlay-b53fbdff8ddc

Best regards,
--  
Stefan Kerkmann <s.kerkmann@pengutronix.de>




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

* [PATCH v2 1/5] of: overlay: of_overlay_fix_path: skip symbols without __overlay__ node
  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
  2026-10-19 10:05 ` [PATCH v2 2/5] of: overlay: fix_path/apply_symbols: add more debugging calls Stefan Kerkmann
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Stefan Kerkmann @ 2026-10-19 10:05 UTC (permalink / raw)
  To: Sascha Hauer, open list:BAREBOX; +Cc: Stefan Kerkmann

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




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

* [PATCH v2 2/5] of: overlay: fix_path/apply_symbols: add more debugging calls
  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 ` [PATCH v2 1/5] of: overlay: of_overlay_fix_path: skip symbols without __overlay__ node Stefan Kerkmann
@ 2026-10-19 10:05 ` Stefan Kerkmann
  2026-10-19 10:05 ` [PATCH v2 3/5] tests: of_overlay: add selftests skeleton Stefan Kerkmann
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Stefan Kerkmann @ 2026-10-19 10:05 UTC (permalink / raw)
  To: Sascha Hauer, open list:BAREBOX; +Cc: Stefan Kerkmann

Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
---
 drivers/of/overlay.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c
index a1df9c3c79..2ee3c040ad 100644
--- a/drivers/of/overlay.c
+++ b/drivers/of/overlay.c
@@ -125,6 +125,8 @@ static char *of_overlay_fix_path(struct device_node *root,
 		return NULL;
 	}
 
+	pr_debug("using fragment %pOF\n", fragment);
+
 	target = find_target(root, fragment, false);
 	if (!target)
 		return ERR_PTR(-EINVAL);
@@ -167,8 +169,8 @@ static int of_overlay_apply_symbols(struct device_node *root,
 		if (!new_path)
 			continue;
 
-		pr_debug("add symbol %s with new path %s\n",
-			 prop->name, new_path);
+		pr_debug("add symbol %s with new path %s (was %s)\n",
+			 prop->name, new_path, old_path);
 		of_property_write_string(root_symbols, prop->name, new_path);
 		free(new_path);
 	}

-- 
2.47.3




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

* [PATCH v2 3/5] tests: of_overlay: add selftests skeleton
  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 ` [PATCH v2 1/5] of: overlay: of_overlay_fix_path: skip symbols without __overlay__ node Stefan Kerkmann
  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 ` Stefan Kerkmann
  2026-10-19 10:05 ` [PATCH v2 4/5] tests: of_overlay: add __symbols__ merging tests Stefan Kerkmann
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Stefan Kerkmann @ 2026-10-19 10:05 UTC (permalink / raw)
  To: Sascha Hauer, open list:BAREBOX; +Cc: Stefan Kerkmann

Add a simple test harness for the upcoming of_overlay selftests.

Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
---
 test/self/Kconfig      |  7 +++++++
 test/self/Makefile     |  1 +
 test/self/of_overlay.c | 16 ++++++++++++++++
 3 files changed, 24 insertions(+)

diff --git a/test/self/Kconfig b/test/self/Kconfig
index 75cfcd1570..bdee21f17d 100644
--- a/test/self/Kconfig
+++ b/test/self/Kconfig
@@ -35,6 +35,7 @@ config SELFTEST_ENABLE_ALL
 	select SELFTEST_CLEANUP
 	select SELFTEST_PROGRESS_NOTIFIER
 	select SELFTEST_OF_MANIPULATION
+	select SELFTEST_OF_OVERLAY
 	select SELFTEST_ENVIRONMENT_VARIABLES if ENVIRONMENT_VARIABLES
 	select SELFTEST_FS_RAMFS if FS_RAMFS
 	select SELFTEST_DIRFD if FS_RAMFS && FS_DEVFS
@@ -97,6 +98,12 @@ config SELFTEST_OF_MANIPULATION
 	help
 	  Tests barebox device tree manipulation functionality
 
+config SELFTEST_OF_OVERLAY
+	bool "OF overlay selftest"
+	select OF_OVERLAY
+	help
+	  Tests devicetree overlay application
+
 config SELFTEST_PROGRESS_NOTIFIER
 	bool "progress notifier selftest"
 
diff --git a/test/self/Makefile b/test/self/Makefile
index c7b5188beb..f912afe5a6 100644
--- a/test/self/Makefile
+++ b/test/self/Makefile
@@ -10,6 +10,7 @@ obj-$(CONFIG_SELFTEST_PRINTF) += printf.o
 CFLAGS_printf.o += -Wno-format-security -Wno-format
 obj-$(CONFIG_SELFTEST_PROGRESS_NOTIFIER) += progress-notifier.o
 obj-$(CONFIG_SELFTEST_OF_MANIPULATION) += of_manipulation.o of_manipulation.dtb.o
+obj-$(CONFIG_SELFTEST_OF_OVERLAY) += of_overlay.o
 obj-$(CONFIG_SELFTEST_ENVIRONMENT_VARIABLES) += envvar.o
 obj-$(CONFIG_SELFTEST_FS_RAMFS) += ramfs.o
 obj-$(CONFIG_SELFTEST_DIRFD) += dirfd.o
diff --git a/test/self/of_overlay.c b/test/self/of_overlay.c
new file mode 100644
index 0000000000..d60898358f
--- /dev/null
+++ b/test/self/of_overlay.c
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <common.h>
+#include <bselftest.h>
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <of.h>
+
+BSELFTEST_GLOBALS();
+
+static void test_of_overlay(void)
+{
+}
+bselftest(core, test_of_overlay);

-- 
2.47.3




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

* [PATCH v2 4/5] tests: of_overlay: add __symbols__ merging tests
  2026-10-19 10:05 [PATCH v2 0/5] of: overlay: fix __symbols__ handling and add selftest suite Stefan Kerkmann
                   ` (2 preceding siblings ...)
  2026-10-19 10:05 ` [PATCH v2 3/5] tests: of_overlay: add selftests skeleton Stefan Kerkmann
@ 2026-10-19 10:05 ` 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
  5 siblings, 0 replies; 7+ messages in thread
From: Stefan Kerkmann @ 2026-10-19 10:05 UTC (permalink / raw)
  To: Sascha Hauer, open list:BAREBOX; +Cc: Stefan Kerkmann

These tests exercise the merging of the __symbols__ table from a overlay
into the target device tree.

Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
---
 test/self/Makefile                     |  3 ++
 test/self/of_overlay.c                 | 90 ++++++++++++++++++++++++++++++++++
 test/self/of_overlay_with_symbols.dts  | 14 ++++++
 test/self/of_overlay_with_symbols.dtso | 43 ++++++++++++++++
 4 files changed, 150 insertions(+)

diff --git a/test/self/Makefile b/test/self/Makefile
index f912afe5a6..f6cec81011 100644
--- a/test/self/Makefile
+++ b/test/self/Makefile
@@ -11,6 +11,9 @@ CFLAGS_printf.o += -Wno-format-security -Wno-format
 obj-$(CONFIG_SELFTEST_PROGRESS_NOTIFIER) += progress-notifier.o
 obj-$(CONFIG_SELFTEST_OF_MANIPULATION) += of_manipulation.o of_manipulation.dtb.o
 obj-$(CONFIG_SELFTEST_OF_OVERLAY) += of_overlay.o
+# Enforce generation of __symbols__ table for overlay tests
+DTC_FLAGS_of_overlay_with_symbols := -@
+obj-$(CONFIG_SELFTEST_OF_OVERLAY) += of_overlay_with_symbols.dtb.o of_overlay_with_symbols.dtbo.o
 obj-$(CONFIG_SELFTEST_ENVIRONMENT_VARIABLES) += envvar.o
 obj-$(CONFIG_SELFTEST_FS_RAMFS) += ramfs.o
 obj-$(CONFIG_SELFTEST_DIRFD) += dirfd.o
diff --git a/test/self/of_overlay.c b/test/self/of_overlay.c
index d60898358f..2804c936c0 100644
--- a/test/self/of_overlay.c
+++ b/test/self/of_overlay.c
@@ -10,7 +10,97 @@
 
 BSELFTEST_GLOBALS();
 
+extern char __dtb_of_overlay_with_symbols_start[],
+	__dtb_of_overlay_with_symbols_end[];
+extern char __dtbo_of_overlay_with_symbols_start[],
+	__dtbo_of_overlay_with_symbols_end[];
+
+static struct device_node *unflatten(char *start, char *end)
+{
+	struct device_node *root;
+
+	root = of_unflatten_dtb(start, end - start);
+	if (IS_ERR(root)) {
+		pr_err("failed to unflatten dtb");
+		return NULL;
+	}
+
+	return root;
+}
+
+static bool test_setup(struct device_node **root, struct device_node **overlay,
+		       char *dtb_start, char *dtb_end, char *dtbo_start,
+		       char *dtbo_end)
+{
+	*root = unflatten(dtb_start, dtb_end);
+	if (!assert_cond(*root != NULL))
+		return false;
+
+	*overlay = unflatten(dtbo_start, dtbo_end);
+	if (!assert_cond(*overlay != NULL)) {
+		of_delete_node(*root);
+		return false;
+	}
+
+	return true;
+}
+
+static void test_of_overlay_symbol_without_overlay(void)
+{
+	struct device_node *root, *overlay, *symbols;
+	const char *path;
+	int ret;
+
+	if (!test_setup(&root, &overlay, __dtb_of_overlay_with_symbols_start,
+			__dtb_of_overlay_with_symbols_end,
+			__dtbo_of_overlay_with_symbols_start,
+			__dtbo_of_overlay_with_symbols_end))
+		return;
+
+	ret = of_overlay_apply_tree(root, overlay);
+	assert_inteq(ret, 0);
+
+	symbols = of_get_child_by_name(root, "__symbols__");
+	assert_cond(symbols != NULL);
+
+	assert_inteq(of_property_read_string(symbols, "added", &path), 0);
+	assert_inteq(of_property_read_string(symbols, "toplevel", &path),
+		     -EINVAL);
+	assert_inteq(of_property_read_string(symbols, "target", &path), 0);
+
+	of_delete_node(overlay);
+	of_delete_node(root);
+}
+
+static void test_of_overlay_symbol_outside_overlay(void)
+{
+	struct device_node *root, *overlay, *symbols;
+	const char *path;
+	int ret;
+
+	if (!test_setup(&root, &overlay, __dtb_of_overlay_with_symbols_start,
+			__dtb_of_overlay_with_symbols_end,
+			__dtbo_of_overlay_with_symbols_start,
+			__dtbo_of_overlay_with_symbols_end))
+		return;
+
+	ret = of_overlay_apply_tree(root, overlay);
+	assert_inteq(ret, 0);
+
+	symbols = of_get_child_by_name(root, "__symbols__");
+	assert_cond(symbols != NULL);
+
+	assert_inteq(of_property_read_string(symbols, "added", &path), 0);
+	assert_inteq(of_property_read_string(symbols, "local", &path), -EINVAL);
+	assert_inteq(of_property_read_string(symbols, "outside", &path), -EINVAL);
+
+	of_delete_node(overlay);
+	of_delete_node(root);
+}
+
 static void test_of_overlay(void)
 {
+	test_of_overlay_symbol_without_overlay();
+	test_of_overlay_symbol_outside_overlay();
 }
 bselftest(core, test_of_overlay);
diff --git a/test/self/of_overlay_with_symbols.dts b/test/self/of_overlay_with_symbols.dts
new file mode 100644
index 0000000000..ac568025ed
--- /dev/null
+++ b/test/self/of_overlay_with_symbols.dts
@@ -0,0 +1,14 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/dts-v1/;
+
+/ {
+	target: target-node {
+		existing-child {
+			old-prop = "old";
+		};
+	};
+
+	phandle_target: phandle-target-node {
+	};
+};
diff --git a/test/self/of_overlay_with_symbols.dtso b/test/self/of_overlay_with_symbols.dtso
new file mode 100644
index 0000000000..9f26e31aee
--- /dev/null
+++ b/test/self/of_overlay_with_symbols.dtso
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/dts-v1/;
+/plugin/;
+
+/ {
+	/* label that ends up in no fragment at all */
+	toplevel: toplevel-node {};
+
+	fragment@0 {
+		target-path = "/target-node";
+
+		__overlay__ {
+			/* label that resolves into an __overlay__ */
+			added: added-by-fragment0 {};
+		};
+	};
+
+	fragment@1 {
+		target-path = "/target-node";
+
+		localinfo {
+			/* label below a fragment but outside its __overlay__ */
+			local: subnode {};
+		};
+
+		__overlay__ {
+			added-by-fragment1 {};
+		};
+	};
+
+	fragment@2 {
+		target-path = "/target-node";
+
+		__overlay__ {
+			added-by-fragment2 {};
+		};
+
+		__overlay__extra {
+			outside: subnode {};
+		};
+	};
+};

-- 
2.47.3




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

* [PATCH v2 5/5] tests: of_overlay: add fragment application tests
  2026-10-19 10:05 [PATCH v2 0/5] of: overlay: fix __symbols__ handling and add selftest suite Stefan Kerkmann
                   ` (3 preceding siblings ...)
  2026-10-19 10:05 ` [PATCH v2 4/5] tests: of_overlay: add __symbols__ merging tests Stefan Kerkmann
@ 2026-10-19 10:05 ` Stefan Kerkmann
  2026-10-20  7:14 ` [PATCH v2 0/5] of: overlay: fix __symbols__ handling and add selftest suite Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Stefan Kerkmann @ 2026-10-19 10:05 UTC (permalink / raw)
  To: Sascha Hauer, open list:BAREBOX; +Cc: Stefan Kerkmann

These tests exercise the application of the overlay fragments by
of_overlay_apply_fragment() with the following test cases:

1. Fragment target is found by target-path and phandle
2. Fragment properties are merged into existing nodes
3. Fragment children without an __overlay__ node are skipped
4. Error path for a fragment whose target does not exist

Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
---
 test/self/Makefile                       |  1 +
 test/self/of_overlay.c                   | 68 ++++++++++++++++++++++++++++++++
 test/self/of_overlay.dtso                | 34 ++++++++++++++++
 test/self/of_overlay_missing_target.dtso | 24 +++++++++++
 4 files changed, 127 insertions(+)

diff --git a/test/self/Makefile b/test/self/Makefile
index f6cec81011..0fba7ac566 100644
--- a/test/self/Makefile
+++ b/test/self/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_SELFTEST_OF_OVERLAY) += of_overlay.o
 # Enforce generation of __symbols__ table for overlay tests
 DTC_FLAGS_of_overlay_with_symbols := -@
 obj-$(CONFIG_SELFTEST_OF_OVERLAY) += of_overlay_with_symbols.dtb.o of_overlay_with_symbols.dtbo.o
+obj-$(CONFIG_SELFTEST_OF_OVERLAY) += of_overlay.dtbo.o of_overlay_missing_target.dtbo.o
 obj-$(CONFIG_SELFTEST_ENVIRONMENT_VARIABLES) += envvar.o
 obj-$(CONFIG_SELFTEST_FS_RAMFS) += ramfs.o
 obj-$(CONFIG_SELFTEST_DIRFD) += dirfd.o
diff --git a/test/self/of_overlay.c b/test/self/of_overlay.c
index 2804c936c0..4c17cae16d 100644
--- a/test/self/of_overlay.c
+++ b/test/self/of_overlay.c
@@ -98,9 +98,77 @@ static void test_of_overlay_symbol_outside_overlay(void)
 	of_delete_node(root);
 }
 
+extern char __dtbo_of_overlay_start[], __dtbo_of_overlay_end[];
+
+static void test_of_overlay_fragments(void)
+{
+	struct device_node *root, *overlay, *node;
+	int ret;
+
+	if (!test_setup(&root, &overlay, __dtb_of_overlay_with_symbols_start,
+			__dtb_of_overlay_with_symbols_end,
+			__dtbo_of_overlay_start, __dtbo_of_overlay_end))
+		return;
+
+	ret = of_overlay_apply_tree(root, overlay);
+	assert_inteq(ret, 0);
+
+	node = of_find_node_by_path_from(root, "/target-node");
+	assert_cond(node != NULL);
+	assert_inteq(of_property_match_string(node, "new-prop", "target-path"),
+		     0);
+	assert_cond(of_get_child_by_name(node, "added-child") != NULL);
+
+	node = of_find_node_by_path_from(root, "/target-node/existing-child");
+	assert_cond(node != NULL);
+	assert_inteq(of_property_match_string(node, "old-prop", "old"), 0);
+	assert_inteq(of_property_match_string(node, "new-prop", "merged"), 0);
+
+	node = of_find_node_by_path_from(root, "/phandle-target-node");
+	assert_cond(node != NULL);
+	assert_inteq(of_property_match_string(node, "new-prop",
+					      "target-phandle"),
+		     0);
+
+	node = of_find_node_by_path_from(root, "/non-fragment-node");
+	assert_cond(node == NULL);
+
+	of_delete_node(overlay);
+	of_delete_node(root);
+}
+
+extern char __dtbo_of_overlay_missing_target_start[],
+	__dtbo_of_overlay_missing_target_end[];
+
+static void test_of_overlay_missing_target(void)
+{
+	struct device_node *root, *overlay, *node;
+	int ret;
+
+	if (!test_setup(&root, &overlay, __dtb_of_overlay_with_symbols_start,
+			__dtb_of_overlay_with_symbols_end,
+			__dtbo_of_overlay_missing_target_start,
+			__dtbo_of_overlay_missing_target_end))
+		return;
+
+	ret = of_overlay_apply_tree(root, overlay);
+	assert_inteq(ret, -ENOENT);
+
+	node = of_find_node_by_path_from(root, "/does-not-exist");
+	assert_cond(node == NULL);
+
+	node = of_find_node_by_path_from(root, "/target-node/applied-anyway");
+	assert_cond(node != NULL);
+
+	of_delete_node(overlay);
+	of_delete_node(root);
+}
+
 static void test_of_overlay(void)
 {
 	test_of_overlay_symbol_without_overlay();
 	test_of_overlay_symbol_outside_overlay();
+	test_of_overlay_fragments();
+	test_of_overlay_missing_target();
 }
 bselftest(core, test_of_overlay);
diff --git a/test/self/of_overlay.dtso b/test/self/of_overlay.dtso
new file mode 100644
index 0000000000..21dc85a8e4
--- /dev/null
+++ b/test/self/of_overlay.dtso
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/dts-v1/;
+/plugin/;
+
+/ {
+	/* not a fragment, must not be applied */
+	non-fragment-node {
+	};
+
+	fragment@0 {
+		target-path = "/target-node";
+
+		__overlay__ {
+			new-prop = "target-path";
+
+			added-child {
+				child-prop;
+			};
+
+			existing-child {
+				new-prop = "merged";
+			};
+		};
+	};
+
+	fragment@1 {
+		target = <&phandle_target>;
+
+		__overlay__ {
+			new-prop = "target-phandle";
+		};
+	};
+};
diff --git a/test/self/of_overlay_missing_target.dtso b/test/self/of_overlay_missing_target.dtso
new file mode 100644
index 0000000000..39362b0a0e
--- /dev/null
+++ b/test/self/of_overlay_missing_target.dtso
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+/dts-v1/;
+/plugin/;
+
+/ {
+	fragment@0 {
+		target-path = "/does-not-exist";
+
+		__overlay__ {
+			never-applied {
+			};
+		};
+	};
+
+	fragment@1 {
+		target-path = "/target-node";
+
+		__overlay__ {
+			applied-anyway {
+			};
+		};
+	};
+};

-- 
2.47.3




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

* Re: [PATCH v2 0/5] of: overlay: fix __symbols__ handling and add selftest suite
  2026-10-19 10:05 [PATCH v2 0/5] of: overlay: fix __symbols__ handling and add selftest suite Stefan Kerkmann
                   ` (4 preceding siblings ...)
  2026-10-19 10:05 ` [PATCH v2 5/5] tests: of_overlay: add fragment application tests Stefan Kerkmann
@ 2026-10-20  7:14 ` Sascha Hauer
  5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2026-10-20  7:14 UTC (permalink / raw)
  To: open list:BAREBOX, Stefan Kerkmann


On Mon, 19 Oct 2026 12:05:43 +0200, Stefan Kerkmann wrote:
> 


Applied, thanks!

[1/5] of: overlay: of_overlay_fix_path: skip symbols without __overlay__ node
      https://git.pengutronix.de/cgit/barebox/commit/?id=f3c88b1eb127 (link may not be stable)
[2/5] of: overlay: fix_path/apply_symbols: add more debugging calls
      https://git.pengutronix.de/cgit/barebox/commit/?id=ccd4ec97f11f (link may not be stable)
[3/5] tests: of_overlay: add selftests skeleton
      https://git.pengutronix.de/cgit/barebox/commit/?id=39a0a5b3d99d (link may not be stable)
[4/5] tests: of_overlay: add __symbols__ merging tests
      https://git.pengutronix.de/cgit/barebox/commit/?id=afc7580916c0 (link may not be stable)
[5/5] tests: of_overlay: add fragment application tests
      https://git.pengutronix.de/cgit/barebox/commit/?id=b913cc2af36e (link may not be stable)

Best regards,
-- 
Sascha Hauer <s.hauer@pengutronix.de>




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

end of thread, other threads:[~2026-10-20  7:15 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v2 1/5] of: overlay: of_overlay_fix_path: skip symbols without __overlay__ node Stefan Kerkmann
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox