From: Simon Glass Date: Wed, 7 Sep 2022 02:27:03 +0000 (-0600) Subject: dm: core: Support writing a property to an empty node X-Git-Url: http://git.dujemihanovic.xyz/img/static/git-favicon.png?a=commitdiff_plain;h=c3a194dec97be3ceb74ba2c980e635aee1644d94;p=u-boot.git dm: core: Support writing a property to an empty node At present this does not work with livetree. Fix it and add a test. Signed-off-by: Simon Glass --- diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index de6327199a..8631e1c286 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -947,9 +947,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) @@ -965,7 +962,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 543dc546b9..0f65ff939f 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -672,6 +672,9 @@ static int dm_test_ofnode_add_subnode(struct unit_test_state *uts) malloc_disable_testing(); } + /* write to the empty node */ + ut_assertok(ofnode_write_string(subnode, "example", "text")); + return 0; } DM_TEST(dm_test_ofnode_add_subnode,