All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] powerpc: Move a dereference below a NULL test
@ 2018-09-26 11:46 zhong jiang
  2018-09-26 13:58 ` Christophe LEROY
  2018-09-26 14:22 ` Michal Suchánek
  0 siblings, 2 replies; 5+ messages in thread
From: zhong jiang @ 2018-09-26 11:46 UTC (permalink / raw)
  To: paulus, benh, mpe; +Cc: linuxppc-dev, linux-kernel

It is safe to move dereference below a NULL test.

Signed-off-by: zhong jiang <zhongjiang@huawei.com>
---
 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,
 		  "cache level mismatch on lookup (got %d, expected %d)\n",
 		  cache->level, level);
 
-	if (!cache)
-		cache = cache_do_one_devnode(node, level);
-
 	return cache;
 }
 
-- 
1.7.12.4


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

* Re: [PATCH] powerpc: Move a dereference below a NULL test
  2018-09-26 11:46 [PATCH] powerpc: Move a dereference below a NULL test zhong jiang
@ 2018-09-26 13:58 ` Christophe LEROY
  2018-09-26 14:06   ` zhong jiang
  2018-09-26 14:22 ` Michal Suchánek
  1 sibling, 1 reply; 5+ messages in thread
From: Christophe LEROY @ 2018-09-26 13:58 UTC (permalink / raw)
  To: zhong jiang, paulus, benh, mpe; +Cc: linuxppc-dev, linux-kernel



Le 26/09/2018 à 13:46, zhong jiang a écrit :
> It is safe to move dereference below a NULL test.
> 
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> ---
>   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);

But by doing this, you change the meaning of the following warning. Is 
that what you want ? In that case the text of the WARN_ONCE() should be 
changed, because the mismatch is not only on lookup now.

Christophe

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

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

* Re: [PATCH] powerpc: Move a dereference below a NULL test
  2018-09-26 13:58 ` Christophe LEROY
@ 2018-09-26 14:06   ` zhong jiang
  0 siblings, 0 replies; 5+ messages in thread
From: zhong jiang @ 2018-09-26 14:06 UTC (permalink / raw)
  To: Christophe LEROY; +Cc: paulus, benh, mpe, linuxppc-dev, linux-kernel

On 2018/9/26 21:58, Christophe LEROY wrote:
>
>
> Le 26/09/2018 à 13:46, zhong jiang a écrit :
>> It is safe to move dereference below a NULL test.
>>
>> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
>> ---
>>   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);
>
> But by doing this, you change the meaning of the following warning. Is that what you want ? In that case the text of the WARN_ONCE() should be changed, because the mismatch is not only on lookup now.
>
Yep, I forget the WARN_ONCE. I think we should just remove it. Thought?

Thanks,
zhong jiang
> Christophe
>
>>         WARN_ONCE(cache && cache->level != level,
>>             "cache level mismatch on lookup (got %d, expected %d)\n",
>>             cache->level, level);
>>   -    if (!cache)
>> -        cache = cache_do_one_devnode(node, level);
>> -
>>       return cache;
>>   }
>>  
>
> .
>



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

* Re: [PATCH] powerpc: Move a dereference below a NULL test
  2018-09-26 11:46 [PATCH] powerpc: Move a dereference below a NULL test zhong jiang
  2018-09-26 13:58 ` Christophe LEROY
@ 2018-09-26 14:22 ` Michal Suchánek
  2018-09-26 14:42   ` zhong jiang
  1 sibling, 1 reply; 5+ messages in thread
From: Michal Suchánek @ 2018-09-26 14:22 UTC (permalink / raw)
  To: zhong jiang; +Cc: paulus, benh, mpe, linuxppc-dev, linux-kernel

On Wed, 26 Sep 2018 19:46:08 +0800
zhong jiang <zhongjiang@huawei.com> wrote:

> It is safe to move dereference below a NULL test.
> 
> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
> ---
>  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

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

* Re: [PATCH] powerpc: Move a dereference below a NULL test
  2018-09-26 14:22 ` Michal Suchánek
@ 2018-09-26 14:42   ` zhong jiang
  0 siblings, 0 replies; 5+ messages in thread
From: zhong jiang @ 2018-09-26 14:42 UTC (permalink / raw)
  To: Michal Suchánek; +Cc: paulus, benh, mpe, linuxppc-dev, linux-kernel

On 2018/9/26 22:22, Michal Suchánek wrote:
> On Wed, 26 Sep 2018 19:46:08 +0800
> zhong jiang <zhongjiang@huawei.com> wrote:
>
>> It is safe to move dereference below a NULL test.
>>
>> Signed-off-by: zhong jiang <zhongjiang@huawei.com>
>> ---
>>  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.
:-[ ,  you're right.  I forget WARN_ONCE.  please ignore the patch.

Sincerely,
zhong jiang
> Thanks
>
> Michal
>
> .
>



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

end of thread, other threads:[~2018-09-26 14:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-26 11:46 [PATCH] powerpc: Move a dereference below a NULL test zhong jiang
2018-09-26 13:58 ` Christophe LEROY
2018-09-26 14:06   ` zhong jiang
2018-09-26 14:22 ` Michal Suchánek
2018-09-26 14:42   ` zhong jiang

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.