All of lore.kernel.org
 help / color / mirror / Atom feed
From: Julia Lawall <julia@diku.dk>
To: "Peter Hüwe" <PeterHuewe@gmx.de>
Cc: Mauro Carvalho Chehab <mchehab@infradead.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org,
	Steven Toth <stoth@kernellabs.com>, Tejun Heo <tj@kernel.org>,
	Dan Carpenter <error27@gmail.com>
Subject: Re: [PATCH] video/saa7164: Fix sparse warning: Using plain integer as NULL pointer
Date: Wed, 26 Jan 2011 06:59:39 +0100 (CET)	[thread overview]
Message-ID: <Pine.LNX.4.64.1101260653450.18314@ask.diku.dk> (raw)
In-Reply-To: <201101252354.31217.PeterHuewe@gmx.de>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1800 bytes --]

On Tue, 25 Jan 2011, Peter Hüwe wrote:

> Am Dienstag 25 Januar 2011, 23:20:44 schrieb Julia Lawall:
> > On Tue, 25 Jan 2011, Peter Huewe wrote:
> > > This patch fixes the warning "Using plain integer as NULL pointer",
> > > generated by sparse, by replacing the offending 0s with NULL.
> > 
> > I recall (a number of years ago) being told that for things like kmalloc,
> > the proper test was !x, not x == NULL.
> > 
> > julia
> > 
> 
> 
> 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?

No.

> Or only for the kmalloc family?
> 
> Do you remember the reason why !x should be preferred?

Because it is a function call, and NULL represents failure of that 
function, not an actual NULL value.

Here is an email that explains that:

http://lkml.org/lkml/2007/7/27/103

Here is the beginning of the thread:

http://lkml.org/lkml/2007/7/27/75

julia

> 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 ;)
> 
> 
> Thanks,
> Peter
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

WARNING: multiple messages have this Message-ID (diff)
From: Julia Lawall <julia@diku.dk>
To: "Peter Hüwe" <PeterHuewe@gmx.de>
Cc: Mauro Carvalho Chehab <mchehab@infradead.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	kernel-janitors@vger.kernel.org,
	Steven Toth <stoth@kernellabs.com>, Tejun Heo <tj@kernel.org>,
	Dan Carpenter <error27@gmail.com>
Subject: Re: [PATCH] video/saa7164: Fix sparse warning: Using plain integer
Date: Wed, 26 Jan 2011 05:59:39 +0000	[thread overview]
Message-ID: <Pine.LNX.4.64.1101260653450.18314@ask.diku.dk> (raw)
In-Reply-To: <201101252354.31217.PeterHuewe@gmx.de>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1877 bytes --]

On Tue, 25 Jan 2011, Peter Hüwe wrote:

> Am Dienstag 25 Januar 2011, 23:20:44 schrieb Julia Lawall:
> > On Tue, 25 Jan 2011, Peter Huewe wrote:
> > > This patch fixes the warning "Using plain integer as NULL pointer",
> > > generated by sparse, by replacing the offending 0s with NULL.
> > 
> > I recall (a number of years ago) being told that for things like kmalloc,
> > the proper test was !x, not x == NULL.
> > 
> > julia
> > 
> 
> 
> 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?

No.

> Or only for the kmalloc family?
> 
> Do you remember the reason why !x should be preferred?

Because it is a function call, and NULL represents failure of that 
function, not an actual NULL value.

Here is an email that explains that:

http://lkml.org/lkml/2007/7/27/103

Here is the beginning of the thread:

http://lkml.org/lkml/2007/7/27/75

julia

> 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 ;)
> 
> 
> Thanks,
> Peter
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

  parent reply	other threads:[~2011-01-26  5:59 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-25 20:54 [PATCH] video/saa7164: Fix sparse warning: Using plain integer as NULL pointer Peter Huewe
2011-01-25 20:54 ` Peter Huewe
2011-01-25 22:20 ` Julia Lawall
2011-01-25 22:20   ` [PATCH] video/saa7164: Fix sparse warning: Using plain integer Julia Lawall
2011-01-25 22:54   ` [PATCH] video/saa7164: Fix sparse warning: Using plain integer as NULL pointer Peter Hüwe
2011-01-25 22:54     ` Peter Hüwe
2011-01-25 23:05     ` Devin Heitmueller
2011-01-25 23:05       ` [PATCH] video/saa7164: Fix sparse warning: Using plain integer as Devin Heitmueller
2011-01-26  0:30       ` [PATCH] video/saa7164: Fix sparse warning: Using plain integer as NULL pointer Andy Walls
2011-01-26  0:30         ` [PATCH] video/saa7164: Fix sparse warning: Using plain integer Andy Walls
2011-01-26  5:59     ` Julia Lawall [this message]
2011-01-26  5:59       ` Julia Lawall
2011-01-26  9:29     ` [PATCH] video/saa7164: Fix sparse warning: Using plain integer as NULL pointer Mauro Carvalho Chehab
2011-01-26  9:29       ` [PATCH] video/saa7164: Fix sparse warning: Using plain integer Mauro Carvalho Chehab
2011-01-30 19:33       ` [PATCH v2] video/saa7164: Fix sparse warning: Using plain integer as NULL pointer Peter Huewe
2011-01-30 19:33         ` Peter Huewe
2011-01-30 20:02         ` Devin Heitmueller
2011-01-30 20:02           ` [PATCH v2] video/saa7164: Fix sparse warning: Using plain integer Devin Heitmueller
2011-01-26  4:25   ` [PATCH] video/saa7164: Fix sparse warning: Using plain integer as NULL pointer Dan Carpenter
2011-01-26  4:25     ` [PATCH] video/saa7164: Fix sparse warning: Using plain integer Dan Carpenter

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=Pine.LNX.4.64.1101260653450.18314@ask.diku.dk \
    --to=julia@diku.dk \
    --cc=PeterHuewe@gmx.de \
    --cc=error27@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@infradead.org \
    --cc=stoth@kernellabs.com \
    --cc=tj@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.