diff options
author | Simon Glass | 2022-09-06 20:27:32 -0600 |
---|---|---|
committer | Tom Rini | 2022-09-29 22:43:43 -0400 |
commit | 0b58eaa89c4d7a4aea1f7f63ff4aca2c2f1d90c4 (patch) | |
tree | 2cfa68b6cbd711ec4ec34e92aa1320930e6a8fd4 /include/dm/ofnode.h | |
parent | 0d63213c1ed5246423c22cbe3c6798a09763a2b9 (diff) |
dm: core: Allow copying ofnode property data when writing
At present ofnode_write_prop() is inconsistent between livetree and
flattree, in that livetree requires the caller to ensure the property
value is stable (e.g. in rodata or allocated) but flattree does not, since
it makes a copy.
This makes the API call a bit painful to use, since the caller must do
different things depending on OF_LIVE.
Add a new 'copy' argument which tells the function to make a copy if
needed. Add some tests to cover this behaviour.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'include/dm/ofnode.h')
-rw-r--r-- | include/dm/ofnode.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 0c5a883eafb..5203045a58e 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1350,19 +1350,23 @@ int ofnode_device_is_compatible(ofnode node, const char *compat); /** * ofnode_write_prop() - Set a property of a ofnode * - * Note that the value passed to the function is *not* allocated by the - * function itself, but must be allocated by the caller if necessary. However - * it does allocate memory for the property struct and name. + * Note that if @copy is false, the value passed to the function is *not* + * allocated by the function itself, but must be allocated by the caller if + * necessary. However it does allocate memory for the property struct and name. * * @node: The node for whose property should be set * @propname: The name of the property to set * @value: The new value of the property (must be valid prior to calling * the function) * @len: The length of the new value of the property + * @copy: true to allocate memory for the value. This only has any effect with + * live tree, since flat tree handles this automatically. It allows a + * node's value to be written to the tree, without requiring that the + * caller allocate it * Return: 0 if successful, -ve on error */ int ofnode_write_prop(ofnode node, const char *propname, const void *value, - int len); + int len, bool copy); /** * ofnode_write_string() - Set a string property of a ofnode |