[PATCH 2/2] of: base: of_new_property(): use xstrdup() instead of strdup()

Antony Pavlov antonynpavlov at gmail.com
Wed Apr 19 03:20:26 PDT 2017


On Mon, 17 Apr 2017 13:42:10 +0300
Antony Pavlov <antonynpavlov at gmail.com> wrote:

> At the moment of_new_property() uses xfunctions for memory
> allocation so we can use xstrdup() instead of strdup()
> for code simplification.
> 
> A side effect of this commmit is that
> the of_new_property() function can't return NULL
> anymore if CONFIG_OFTREE is set.

If of_new_property() can't return NULL we can skip all numerous
checks after of_new_property() call. So the checks are actual only
if CONFIG_OFTREE isn't set.

Have you any sugestions on removing of_new_property() return value checks?


> Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
> ---
>  drivers/of/base.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/drivers/of/base.c b/drivers/of/base.c
> index 1161ce9793..c9bdd91810 100644
> --- a/drivers/of/base.c
> +++ b/drivers/of/base.c
> @@ -1802,12 +1802,7 @@ 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->name = xstrdup(name);
>  	prop->length = len;
>  	prop->value = xzalloc(len);
>  
> -- 
> 2.11.0
> 


-- 
Best regards,
  Antony Pavlov



More information about the barebox mailing list