[PATCH 1/3] OF: base: add sanity checks to of_new/delete_property

Sascha Hauer s.hauer at pengutronix.de
Sun Jun 23 14:24:04 EDT 2013


On Fri, Jun 21, 2013 at 05:15:16PM +0200, Sebastian Hesselbarth wrote:
> This adds some sanity checks to of_new_property and of_delete_property.
> Also, data passed to of_new_property is only copied if non-NULL.
> 
> Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth at gmail.com>
> ---
> Cc: barebox at lists.infradead.org
> ---
>  drivers/of/base.c |   18 +++++++++++++++++-
>  1 files changed, 17 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 1b351ee..bcfd73a 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1527,21 +1527,37 @@ struct property *of_new_property(struct device_node *node, const char *name,
>  	struct property *prop;
>  
>  	prop = xzalloc(sizeof(*prop));
> +	if (!prop)
> +		return NULL;

xzalloc always returns valid memory. It's return-mem-or-panic.

>  
>  	prop->name = strdup(name);
> +	if (!prop->name)
> +		goto bail_out;
> +
>  	prop->length = len;
>  	if (len) {
>  		prop->value = xzalloc(len);
> -		memcpy(prop->value, data, len);
> +		if (!prop->value)
> +			goto bail_out;

ditto.

Sascha

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



More information about the barebox mailing list