mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Colin King <colin.king@canonical.com>
Cc: Stuart Yoder <stuyoder@gmail.com>,
	Laurentiu Tudor <laurentiu.tudor@nxp.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Wei Yongjun <weiyongjun1@huawei.com>,
	devel@driverdev.osuosl.org, kernel-janitors@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] staging: fsl-mc: fix fsl_mc_is_allocatable strcmps
Date: Wed, 16 Aug 2017 15:06:54 +0300	[thread overview]
Message-ID: <20170816120654.p3mpezb3zr2eqxvw@mwanda> (raw)
In-Reply-To: <20170816114451.1348-1-colin.king@canonical.com>

On Wed, Aug 16, 2017 at 12:44:51PM +0100, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The previous fix removed the equal to zero comparisons by the strcmps and
> now the function always returns true. Fix this by adding in the missing
> logical negation operators.
> 
> Detected by CoverityScan, CID#1452267 ("Constant expression result")
> 
> Fixes: b93ad9a067e1 ("staging: fsl-mc: be consistent when checking strcmp() return")

Ugh...  I did review the original patch at all.  Sorry.  It's better to
use "== 0" because it's idiomatic.

	strcmp(foo, bar) == 0 means foo == bar
	strcmp(foo, bar) != 0 means foo != bar
	strcmp(foo, bar) < 0 means foo < bar alphabetically.

It's way more readable.  strcmp() bugs are fairly common when people
don't use == 0 and != 0.  There are other places where != 0 hurts
readability, such as checking for errors:

	if (frob() != 0) {

In this case, frob() is returning negative error codes, but it's not
really returning the number zero, it's returning "success".  So it
should be:

	ret = frob();
	if (ret) {

Comparing against NULL really doesn't add anything either.  But if
you're talking about the number zero then you should use == 0.

	if (len == 0)
		return 0;

regards,
dan carpenter

  reply	other threads:[~2017-08-16 12:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-16 11:44 Colin King
2017-08-16 12:06 ` Dan Carpenter [this message]
2017-08-16 12:10   ` Dan Carpenter
2017-08-16 13:37   ` Laurentiu Tudor
2017-08-16 14:14     ` Colin Ian King

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=20170816120654.p3mpezb3zr2eqxvw@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=colin.king@canonical.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=laurentiu.tudor@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stuyoder@gmail.com \
    --cc=weiyongjun1@huawei.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

all inboxes | Powered by JetHome®