[PATCH v2 1/2] OF: base: add sanity checks to of_new/delete_property
Sebastian Hesselbarth
sebastian.hesselbarth at gmail.com
Mon Jun 24 06:49:20 EDT 2013
This adds some sanity checks to of_new_property and of_delete_property.
Also, value pointer is always allocated even with zero length to allow
empty properties to be distinguished from non-existing properties.
Finally, data passed to of_new_property is only copied if non-NULL.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
---
Note: Patch 3 of the former patch set has been dropped in favour of zero
length allocation here.
Changelog:
v1->v2:
- remove unneccesary NULL checks after xzalloc (Suggested by Sascha Hauer)
- allocate zero length value pointer (Suggested by Sascha Hauer)
Cc: barebox at lists.infradead.org
---
drivers/of/base.c | 15 +++++++++++----
1 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index 1b351ee..e65cf85 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1527,13 +1527,17 @@ struct property *of_new_property(struct device_node *node, const char *name,
struct property *prop;
prop = xzalloc(sizeof(*prop));
-
prop->name = strdup(name);
+ if (!prop->name) {
+ free(prop);
+ return NULL;
+ }
+
prop->length = len;
- if (len) {
- prop->value = xzalloc(len);
+ prop->value = xzalloc(len);
+
+ if (data)
memcpy(prop->value, data, len);
- }
list_add_tail(&prop->list, &node->properties);
@@ -1542,6 +1546,9 @@ struct property *of_new_property(struct device_node *node, const char *name,
void of_delete_property(struct property *pp)
{
+ if (!pp)
+ return;
+
list_del(&pp->list);
free(pp->name);
--
1.7.2.5
More information about the barebox
mailing list