]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: Support writing a property to an empty node
authorSimon Glass <sjg@chromium.org>
Wed, 7 Sep 2022 02:27:03 +0000 (20:27 -0600)
committerTom Rini <trini@konsulko.com>
Thu, 29 Sep 2022 20:07:58 +0000 (16:07 -0400)
At present this does not work with livetree. Fix it and add a test.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/core/of_access.c
test/dm/ofnode.c

index de6327199a2e76b85352897992106b0168416f4d..8631e1c286b548bd7090d0a6a3dc6f356962f06d 100644 (file)
@@ -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;
 }
index 543dc546b95e016be24d7a778edebdf55d4b3e8d..0f65ff939fb934191fb29c17a051d9e6c125f5ec 100644 (file)
@@ -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,