Re: [PATCH] video/saa7164: Fix sparse warning: Using plain integer as NULL pointer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux