Subject: Re: [PATCH] powerpc: Move a dereference below a NULL test

From: Michal Suchánek <[email-masked]>
Date: Wed, 26 Sep 2018 16:22:32 +0200

On Wed, 26 Sep 2018 19:46:08 +0800
zhong jiang <[email-masked]> wrote:

> It is safe to move dereference below a NULL test.
> 
> Signed-off-by: zhong jiang <[email-masked]>
> ---
>  arch/powerpc/kernel/cacheinfo.c | 5 ++---
>  1 file changed, 2 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/powerpc/kernel/cacheinfo.c
> b/arch/powerpc/kernel/cacheinfo.c index a8f20e5..7f19714 100644
> --- a/arch/powerpc/kernel/cacheinfo.c
> +++ b/arch/powerpc/kernel/cacheinfo.c
> @@ -401,14 +401,13 @@ static struct cache
> *cache_lookup_or_instantiate(struct device_node *node, struct cache
> *cache; 
>  	cache = cache_lookup_by_node(node);
> +	if (!cache)
> +		cache = cache_do_one_devnode(node, level);
>  
>  	WARN_ONCE(cache && cache->level != level,

This has also null test so cache should be dereferenced only when
non-null here.

Thanks

Michal