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 <sjg@chromium.org>
This commit is contained in:
Simon Glass
2022-09-06 20:27:03 -06:00
committed by Tom Rini
parent ffe9039249
commit c3a194dec9
2 changed files with 7 additions and 4 deletions

View 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;
}

View 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,