[PATCH 09/21] dm: core: Support writing a property to an empty node

Simon Glass sjg at chromium.org
Wed Aug 31 05:08:05 CEST 2022


At present this does not work with livetree. Fix it and add a test.

Signed-off-by: Simon Glass <sjg at chromium.org>
---

 drivers/core/of_access.c | 8 ++++----
 test/dm/ofnode.c         | 3 +++
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c
index 765b21cecdb..cc5837a4a3b 100644
--- a/drivers/core/of_access.c
+++ b/drivers/core/of_access.c
@@ -909,9 +909,6 @@ int of_write_prop(struct device_node *np, const char *propname, int len,
 		pp_last = pp;
 	}
 
-	if (!pp_last)
-		return -ENOENT;
-
 	/* Property does not exist -> append new property */
 	new = malloc(sizeof(struct property));
 	if (!new)
@@ -927,7 +924,10 @@ int of_write_prop(struct device_node *np, const char *propname, int len,
 	new->length = len;
 	new->next = NULL;
 
-	pp_last->next = new;
+	if (pp_last)
+		pp_last->next = new;
+	else
+		np->properties = new;
 
 	return 0;
 }
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index f5aabf42dbb..76346e37d1f 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -612,6 +612,9 @@ static int dm_test_ofnode_add_subnode(struct unit_test_state *uts)
 	check = ofnode_path("/lcd/edmund");
 	ut_asserteq(check.of_offset, subnode.of_offset);
 
+	/* write to the empty node */
+	ut_assertok(ofnode_write_string(subnode, "compatible", "sandbox,usb"));
+
 	ut_asserteq(-EEXIST, ofnode_add_subnode(node, "edmund", &subnode));
 
 	return 0;
-- 
2.37.2.672.g94769d06f0-goog



More information about the U-Boot mailing list