arch/powerpc/kernel/cacheinfo.c: Possible null pointer dereference

Michael Ellerman michael at ellerman.id.au
Mon Feb 14 10:24:30 EST 2011


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://lists.ozlabs.org/pipermail/linuxppc-dev/attachments/20110214/2fdf55bf/attachment.pgp>


More information about the Linuxppc-dev mailing list