From: Sascha Hauer <s.hauer@pengutronix.de>
To: Masahiro Yamada <yamada.m@jp.panasonic.com>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2] param: add error check to __dev_add_param()
Date: Fri, 30 Jan 2015 08:44:53 +0100 [thread overview]
Message-ID: <20150130074453.GR12209@pengutronix.de> (raw)
In-Reply-To: <20150129194731.3DAE.AA925319@jp.panasonic.com>
On Thu, Jan 29, 2015 at 07:47:31PM +0900, Masahiro Yamada wrote:
> Hi Sascha,
>
> On Thu, 29 Jan 2015 10:32:12 +0100
> > > > > @@ -130,6 +130,13 @@ static int __dev_add_param(struct param_d *param, struct device_d *dev, const ch
> > > > > if (get_param_by_name(dev, name))
> > > > > return -EEXIST;
> > > > >
> > > > > + if (!name)
> > > > > + return -EINVAL;
> > > >
> > > > Name is used already two lines above so barebox will already be crashed
> > > > before this triggers.
> > > >
> > > > 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.
> > > >
> > >
> > > OK, then how about dropping this -EINVAL check?
> >
> > Yes, please.
>
>
> I did that in v3.
>
>
> > >
> > > I think the -ENOMEM check below is still useful.
> > > ( strdup() returns NULL also when NULL is passed,
> > > but in that case this line cannot be reached.
> > > The problem is that is not apparent at a glance..)
> >
> > Note we also have xstrdup which crashes barebox on out of memory. This
> > is usually the right thing to do when it's known that the allocation is
> > small.
> >
>
> I stopped and I have been thinking about it.
> I hesitate a bit to replace it with xstrdup(). I feel like being lazy.
>
> So, I did not do this in v3.
The name of the parameter can be passed in by the user via the 'global'
command, so using strdup instead seems like a good idea here.
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 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-01-30 7:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-29 2:46 Masahiro Yamada
2015-01-29 9:06 ` Sascha Hauer
2015-01-29 9:21 ` Masahiro Yamada
2015-01-29 9:32 ` Sascha Hauer
2015-01-29 10:47 ` Masahiro Yamada
2015-01-30 7:44 ` Sascha Hauer [this message]
2015-01-29 10:51 ` Masahiro Yamada
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=20150130074453.GR12209@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=yamada.m@jp.panasonic.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