From: Dan Carpenter <dan.carpenter@oracle.com>
To: Sidong Yang <realwakka@gmail.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: vboxvideo: vbox_main: Remove unnecessary local variable
Date: Thu, 10 Jan 2019 22:44:08 +0300 [thread overview]
Message-ID: <20190110192942.GF1718@kadam> (raw)
In-Reply-To: <20190110170023.4vcyws3ktsf2sz3g@raspberrypi>
On Thu, Jan 10, 2019 at 05:00:24PM +0000, Sidong Yang wrote:
> I think you just point out that my code isn't obvious because the
> function returns negative error codes. I agree with you. But what if
> change my code like if(hgsmi_query_conf() != 0).
>
That's even worse! :P
You should do comparisons with zero when you are talking about zero
meaning the number zero. In this case, hgsmi_query_conf() returns "zezro
meaning success" not "zero meaning the number zero". How many bytes?
Zero. That is the number zero.
!= zero is a double negative, because NOT and ZERO are negatives. If
double negatives simplified the code we would add four of them instead
of just the one:
if ((((hgsmi_query_conf() != 0) != 0) != 0) != 0) {
See? Adding != 0 doesn't make it simpler...
The other place where != 0 is appropriate besides talking about the
number is when you're using a strcmp() function because it works like
this:
if (strcmp(a, b) < 0) { <-- means a < b
if (strcmp(a, b) == 0) { <-- means a == b
if (strcmp(a, b) != 0) { <-- means a != b
regards,
dan carpenter
next prev parent reply other threads:[~2019-01-10 19:44 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-10 6:13 [PATCH] staging: vboxvideo: vbox_main: Remove unnecessary local variable Sidong Yang
2019-01-10 12:23 ` Dan Carpenter
2019-01-10 17:00 ` Sidong Yang
2019-01-10 19:44 ` Dan Carpenter [this message]
2019-01-11 3:36 ` Sidong Yang
2019-01-11 9:42 ` Greg Kroah-Hartman
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=20190110192942.GF1718@kadam \
--to=dan.carpenter@oracle.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=realwakka@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