mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2 1/2] OF: base: add sanity checks to of_new/delete_property
Date: Mon, 24 Jun 2013 21:40:14 +0200	[thread overview]
Message-ID: <20130624194014.GU32299@pengutronix.de> (raw)
In-Reply-To: <1372070961-10132-1-git-send-email-sebastian.hesselbarth@gmail.com>

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@gmail.com>

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@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
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> 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@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2013-06-24 19:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-21 15:15 [PATCH 0/3] OF: base: cleanup and allow empty properties Sebastian Hesselbarth
2013-06-21 15:15 ` [PATCH 1/3] OF: base: add sanity checks to of_new/delete_property Sebastian Hesselbarth
2013-06-23 18:24   ` Sascha Hauer
2013-06-21 15:15 ` [PATCH 2/3] OF: base: use of_delete_property where applicable Sebastian Hesselbarth
2013-06-21 15:15 ` [PATCH 3/3] OF: base: add empty property value pointer Sebastian Hesselbarth
2013-06-23 18:33   ` Sascha Hauer
2013-06-23 20:11     ` Sebastian Hesselbarth
2013-06-23 20:26       ` Sascha Hauer
2013-06-23 20:29         ` Sebastian Hesselbarth
2013-06-24 10:49 ` [PATCH v2 1/2] OF: base: add sanity checks to of_new/delete_property Sebastian Hesselbarth
2013-06-24 19:40   ` Sascha Hauer [this message]
2013-06-24 10:49 ` [PATCH v2 2/2] OF: base: use of_delete_property where applicable Sebastian Hesselbarth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130624194014.GU32299@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=sebastian.hesselbarth@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox