[PATCH v2] param: add error check to __dev_add_param()

Masahiro Yamada yamada.m at jp.panasonic.com
Thu Jan 29 02:51:15 PST 2015


Hi Sascha,



On Thu, 29 Jan 2015 10:06:22 +0100
Sascha Hauer <s.hauer at pengutronix.de> wrote:

> Besides, I normally don't like these checks. dereferencing NULL pointers
> means you get a backtrace showing you what went wrong. Returning an error
> means adding code which in this case makes dev_add_param just fail
> silently because the return value often is not checked.
> 

What a coincidence!
Actually, I was writing the following patch yesterday:




> Author: Masahiro Yamada <yamada.m at jp.panasonic.com>
> Date:   Wed Jan 28 22:07:59 2015 +0900
> 
>     param: do not search NULL-named parameter
>     
>     If the argument name is given with NULL, it is passed to strcmp()
>     resulting in NULL-pointer access.  It would be safer to return NULL
>     (which means "Not found") in such a case.
>     
>     Signed-off-by: Masahiro Yamada <yamada.m at jp.panasonic.com>
> 
> diff --git a/lib/parameter.c b/lib/parameter.c
> index 865ad9f..c37d877 100644
> --- a/lib/parameter.c
> +++ b/lib/parameter.c
> @@ -33,6 +33,9 @@ struct param_d *get_param_by_name(struct device_d *dev, const char *name)
>  {
>         struct param_d *p;
>  
> +       if (!name)
> +               return NULL;
> +
>         list_for_each_entry(p, &dev->parameters, list) {
>                 if (!strcmp(p->name, name))
>                         return p;


Do you mean, you do not like such a patch?



Best Regards
Masahiro Yamada




More information about the barebox mailing list