[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20151202135930.GM7289@mwanda>
Date: Wed, 2 Dec 2015 16:59:30 +0300
From: Dan Carpenter <dan.carpenter@...cle.com>
To: Alexander Zarochentsev <alexander.zarochentsev@...gate.com>
Cc: James Simmons <jsimmons@...radead.org>, devel@...verdev.osuosl.org,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
Oleg Drokin <oleg.drokin@...el.com>,
Amir Shehata <amir.shehata@...el.com>,
lustre-devel@...ts.lustre.org
Subject: Re: [lustre-devel] [PATCH 21/40] staging: lustre: improve LNet clean
up code and API
On Wed, Dec 02, 2015 at 04:20:59PM +0300, Alexander Zarochentsev wrote:
> > BAD: if (rc != 0)
> > GOOD: if (rc)
>
> The latest suggestion is not correct,
> from http://wiki.lustre.org/Lustre_Coding_Guidelines :
> Conditional boolean (if (expr)), scalar (if (val != 0)) and pointer
> (if (ptr != NULL)) expressions should be written consistently.
Kernel style trumps Lustre style. Double negative don't not hurt
readability. != NULL is a checkpatch.pl warning. Also comparisons like
== false or == true are checkpatch warnings.
I can think of two places where comparing with zero is appropriate and
those are:
1) If you are talking about the numer zero.
if (x == 0 || x == 2)
2) strcmp() and other *cmp() functions.
if (strcmp(foo, bar) == 0) /* foo and bar are the same */
if (strcmp(foo, bar) < 0) /* foo less than bar */
if (strcmp(foo, bar) != 0) /* foo not the same as bar */
For "if (rc) {" a zero return doesn't mean zero, it means success so
comparing against zero is bad style.
regards,
dan carpenter
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists