From: Dan Carpenter <dan.carpenter@oracle.com>
To: Stephan Gabert <stephan.gabert@fau.de>
Cc: pe1dnn@amsat.org, gregkh@linuxfoundation.org,
devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org,
nicolas.pfeiffer@fau.de, linux-kernel@i4.cs.fau.de
Subject: Re: [PATCH 3/5] staging/wlags49_h2: correct check of the return value of register_netdev()
Date: Mon, 16 Jun 2014 21:49:03 +0300 [thread overview]
Message-ID: <20140616184903.GH5500@mwanda> (raw)
In-Reply-To: <1402930253-32537-4-git-send-email-stephan.gabert@fau.de>
On Mon, Jun 16, 2014 at 04:50:51PM +0200, Stephan Gabert wrote:
> As mentioned in net/core/dev.c register_netdev() explicitly returns a
> negative errno code on failure.
>
> So in case of failure, one should rather test whether ret is negative
> than just unlike 0.
No. In the kernel the normal way is to say:
if (ret)
return ret;
Zero is succes and non-zero is error code.
if (ret != 0)
return ret;
That's a double negative and pointlessly confusing.
if (ret != 0 != 0 != 0)
That's a hextuple negative and awesomely confusing.
There are times where a double negative is ok. When you are talking
about numbers specifically:
if (ret != 0 && ret != 3) {
That means ret is not zero or three, but zero doesn't mean success or
failure, it's just a number.
For strcmp() functions you should always compare against zero
because that is the idiom.
if (strcmp(foo, bar) < 0)
if (strcmp(foo, bar) != 0)
The first "<" means "foo" is before "bar" and "!=" means not equal.
if (ret < 0)
return ret;
Probably means that now ret is either zero or a positive value??? It is
ambiguous.
regards,
dan carpenter
next prev parent reply other threads:[~2014-06-16 18:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-16 14:50 [PATCH 0/5] staging/wlags49_h2: fixed up wl_cs.c Stephan Gabert
2014-06-16 14:50 ` [PATCH 1/5] staging/wlags49_h2: checkpatch: including <linux/*.h> instead of <asm/*.h> Stephan Gabert
2014-06-16 14:50 ` [PATCH 2/5] staging/wlags49_h2: checkpatch: added spaces around equal sign Stephan Gabert
2014-06-16 14:50 ` [PATCH 3/5] staging/wlags49_h2: correct check of the return value of register_netdev() Stephan Gabert
2014-06-16 18:49 ` Dan Carpenter [this message]
2014-06-16 14:50 ` [PATCH 4/5] staging/wlags49_h2: convert printk calls to netdev_* calls Stephan Gabert
2014-06-16 14:50 ` [PATCH 5/5] staging/wlags49_h2: checkpatch: line over 80 characters Stephan Gabert
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=20140616184903.GH5500@mwanda \
--to=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@i4.cs.fau.de \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.pfeiffer@fau.de \
--cc=pe1dnn@amsat.org \
--cc=stephan.gabert@fau.de \
/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