linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* arch/powerpc/kernel/cacheinfo.c: Possible null pointer dereference
@ 2011-02-12 10:08 David Binderman
  2011-02-13 23:24 ` Michael Ellerman
  0 siblings, 1 reply; 2+ messages in thread
From: David Binderman @ 2011-02-12 10:08 UTC (permalink / raw)
  To: benh, paulus; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 538 bytes --]


Hello there,

I just tried out cppcheck-1.47 on the linux-2.6.38-rc4 source code.

It said

[arch/powerpc/kernel/cacheinfo.c:380]: (error) Possible null pointer dereference: cache - otherwise it is redundant to check if cache is null at line 382

The source code is

    WARN_ONCE(cache && cache->level != level,
          "cache level mismatch on lookup (got %d, expected %d)\n",
          cache->level, level);

    if (!cache)

I agree with cppcheck. Suggest code rework.

Regards

David Binderman

 		 	   		  

[-- Attachment #2: Type: text/html, Size: 913 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: arch/powerpc/kernel/cacheinfo.c: Possible null pointer dereference
  2011-02-12 10:08 arch/powerpc/kernel/cacheinfo.c: Possible null pointer dereference David Binderman
@ 2011-02-13 23:24 ` Michael Ellerman
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Ellerman @ 2011-02-13 23:24 UTC (permalink / raw)
  To: David Binderman; +Cc: paulus, linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 861 bytes --]

On Sat, 2011-02-12 at 10:08 +0000, David Binderman wrote:
> Hello there,
> 
> I just tried out cppcheck-1.47 on the linux-2.6.38-rc4 source code.
> 
> It said
> 
> [arch/powerpc/kernel/cacheinfo.c:380]: (error) Possible null pointer
> dereference: cache - otherwise it is redundant to check if cache is
> null at line 382
> 
> The source code is
> 
>     WARN_ONCE(cache && cache->level != level,
>           "cache level mismatch on lookup (got %d, expected %d)\n",
>           cache->level, level);
> 
>     if (!cache)
> 
> I agree with cppcheck. Suggest code rework.

It's wrong.

The code is essentially:

if (cache && cache->level != level)
	printf("cache level mismatch on lookup (got %d, expected %d)\n", cache->level, level);

if (!cache)
	cache = cache_do_one_devnode(node, level);


Which looks fine to me?

cheers

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-02-13 23:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-12 10:08 arch/powerpc/kernel/cacheinfo.c: Possible null pointer dereference David Binderman
2011-02-13 23:24 ` Michael Ellerman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).