[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <AANLkTinap-4djdUORmOnnnVFtTm4wSxMqTNVxrfg2jYw@mail.gmail.com>
Date: Tue, 25 Jan 2011 18:05:37 -0500
From: Devin Heitmueller <dheitmueller@...nellabs.com>
To: Peter Hüwe <PeterHuewe@....de>
Cc: Julia Lawall <julia@...u.dk>,
Mauro Carvalho Chehab <mchehab@...radead.org>,
linux-media@...r.kernel.org, linux-kernel@...r.kernel.org,
kernel-janitors@...r.kernel.org,
Steven Toth <stoth@...nellabs.com>, Tejun Heo <tj@...nel.org>,
Dan Carpenter <error27@...il.com>
Subject: Re: [PATCH] video/saa7164: Fix sparse warning: Using plain integer as
NULL pointer
On Tue, Jan 25, 2011 at 5:54 PM, Peter Hüwe <PeterHuewe@....de> wrote:
> Hi Julia,
>
> thanks for your input.
> So do I understand you correctly if I say
> if(!x) is better than if(x==NULL) in any case?
>
> Or only for the kmalloc family?
>
> Do you remember the reason why !x should be preferred?
>
> In Documentation/CodingStyle , Chapter 7: Centralized exiting of functions
> there is a function fun with looks like this:
> int fun(int a)
> {
> int result = 0;
> char *buffer = kmalloc(SIZE);
>
> if (buffer == NULL)
> return -ENOMEM;
>
> if (condition1) {
> while (loop1) {
> ...
> }
> result = 1;
> goto out;
> }
> ...
> out:
> kfree(buffer);
> return result;
> }
>
>
> --> So if (buffer == NULL) is in the official CodingStyle - maybe we should
> add a paragraph there as well ;)
>
>
> Don't get me wrong, I just want to learn ;)
To my knowledge, the current CodingStyle doesn't enforce a particular
standard in this regard, leaving it at the discretion of the author.
Whether to do (!foo) or (foo == NULL) is one of those debates people
have similar to whether to use tabs as whitespace. People have
differing opinions and there is no clearly "right" answer. Personally
I strongly prefer (foo == NULL) as it makes it blindingly obvious that
it's a pointer comparison, whereas (!foo) leaves you wondering whether
it's an integer or pointer comparison.
All that said, you shouldn't submit patches which arbitrarily change
from one format to the other. With regards to the proposed patch, you
should follow whatever style the author employed in the rest of the
file.
Cheers,
Devin
--
Devin J. Heitmueller - Kernel Labs
http://www.kernellabs.com
--
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