[PATCH 03/22] OF: base: also update property length on of_property_write_u32

Sebastian Hesselbarth sebastian.hesselbarth at gmail.com
Tue Jun 18 13:29:48 EDT 2013


Current implementation of of_property_write_u32 does free old property
values and allocates new values depending on the size passed. While
copying the new values to the property, corresponding length is not
set. This makes of_property_write_u32 set the length of the new property
values and also adds a API header describing the function.

Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Cc: barebox at lists.infradead.org
---
 drivers/of/base.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index ab0f4cd..616b93d 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -383,6 +383,21 @@ int of_property_read_u32_array(const struct device_node *np,
 }
 EXPORT_SYMBOL_GPL(of_property_read_u32_array);
 
+/**
+ * of_property_write_u32_array - Write an array of u32 to a property. If
+ * the property does not exist, it will be created and appended to the given
+ * device node.
+ *
+ * @np:		device node to which the property value is to be written.
+ * @propname:	name of the property to be written.
+ * @values:	pointer to array elements to write.
+ * @sz:		number of array elements to write.
+ *
+ * Search for a property in a device node and write 32-bit value(s) to
+ * it. If the property does not exist, it will be created and appended to
+ * the device node. Returns 0 on success, -ENOMEM if the property or array
+ * of elements cannot be created.
+ */
 int of_property_write_u32_array(struct device_node *np,
 				const char *propname, const u32 *values,
 				size_t sz)
@@ -397,14 +412,15 @@ int of_property_write_u32_array(struct device_node *np,
 
 	free(prop->value);
 
-	prop->value = malloc(sizeof(__be32) * sz);
+	prop->length = sizeof(*val) * sz;
+	prop->value = malloc(prop->length);
 	if (!prop->value)
 		return -ENOMEM;
 
 	val = prop->value;
-
 	while (sz--)
 		*val++ = cpu_to_be32(*values++);
+
 	return 0;
 }
 
-- 
1.7.2.5




More information about the barebox mailing list