On Mon, Jun 24, 2013 at 12:49:20PM +0200, Sebastian Hesselbarth wrote: > 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@xxxxxxxxx> Applied both. Thanks Sascha > --- > 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@xxxxxxxxxxxxxxxxxxx > --- > 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 > > > _______________________________________________ > barebox mailing list > barebox@xxxxxxxxxxxxxxxxxxx > http://lists.infradead.org/mailman/listinfo/barebox > -- Pengutronix e.K. | | Industrial Linux Solutions | http://www.pengutronix.de/ | Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox