mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/platform/olpc: remove duplicated check on node == -1
@ 2018-12-09 15:01 Colin King
  2018-12-09 17:10 ` Christophe JAILLET
  2018-12-09 17:13 ` Christophe JAILLET
  0 siblings, 2 replies; 4+ messages in thread
From: Colin King @ 2018-12-09 15:01 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, H . Peter Anvin,
	x86, Andrew Morton
  Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

Currently the node == -1 check is being performed twice, the
second check is redundant and can be removed.  Fix this by
removing the redundant second check and moving the first check
into a combined check with the result from the olpc_ofw call.

Detected by cppcheck:
Identical condition '(s32)node==-1', second condition is always false

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 arch/x86/platform/olpc/olpc_dt.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
index b4ab779f1d47..658363ec3ff3 100644
--- a/arch/x86/platform/olpc/olpc_dt.c
+++ b/arch/x86/platform/olpc/olpc_dt.c
@@ -28,10 +28,7 @@ static phandle __init olpc_dt_getsibling(phandle node)
 	const void *args[] = { (void *)node };
 	void *res[] = { &node };
 
-	if ((s32)node == -1)
-		return 0;
-
-	if (olpc_ofw("peer", args, res) || (s32)node == -1)
+	if (((s32)node == -1) || olpc_ofw("peer", args, res))
 		return 0;
 
 	return node;
-- 
2.19.1


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

* Re: [PATCH] x86/platform/olpc: remove duplicated check on node == -1
  2018-12-09 15:01 [PATCH] x86/platform/olpc: remove duplicated check on node == -1 Colin King
@ 2018-12-09 17:10 ` Christophe JAILLET
  2018-12-09 17:13 ` Christophe JAILLET
  1 sibling, 0 replies; 4+ messages in thread
From: Christophe JAILLET @ 2018-12-09 17:10 UTC (permalink / raw)
  To: linux-kernel; +Cc: kernel-janitors

Le 09/12/2018 à 16:01, Colin King a écrit :
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently the node == -1 check is being performed twice, the
> second check is redundant and can be removed.  Fix this by
> removing the redundant second check and moving the first check
> into a combined check with the result from the olpc_ofw call.
>
> Detected by cppcheck:
> Identical condition '(s32)node==-1', second condition is always false
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   arch/x86/platform/olpc/olpc_dt.c | 5 +----
>   1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
> index b4ab779f1d47..658363ec3ff3 100644
> --- a/arch/x86/platform/olpc/olpc_dt.c
> +++ b/arch/x86/platform/olpc/olpc_dt.c
> @@ -28,10 +28,7 @@ static phandle __init olpc_dt_getsibling(phandle node)
>   	const void *args[] = { (void *)node };
>   	void *res[] = { &node };
>   
> -	if ((s32)node == -1)
> -		return 0;
> -
> -	if (olpc_ofw("peer", args, res) || (s32)node == -1)
> +	if (((s32)node == -1) || olpc_ofw("peer", args, res))
>   		return 0;
>   
>   	return node;

'res' is { &node }

Could 'node' be modified by 'olpc_ofw(..., res)' and set to -1?

In other words, I'm not sure that the 2nd check is a redundant here.

Just my 2c,

CJ



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

* Re: [PATCH] x86/platform/olpc: remove duplicated check on node == -1
  2018-12-09 15:01 [PATCH] x86/platform/olpc: remove duplicated check on node == -1 Colin King
  2018-12-09 17:10 ` Christophe JAILLET
@ 2018-12-09 17:13 ` Christophe JAILLET
  2018-12-09 17:30   ` NACK: " Colin Ian King
  1 sibling, 1 reply; 4+ messages in thread
From: Christophe JAILLET @ 2018-12-09 17:13 UTC (permalink / raw)
  To: Colin King, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H . Peter Anvin, x86, Andrew Morton
  Cc: kernel-janitors, linux-kernel

Le 09/12/2018 à 16:01, Colin King a écrit :
> From: Colin Ian King <colin.king@canonical.com>
>
> Currently the node == -1 check is being performed twice, the
> second check is redundant and can be removed.  Fix this by
> removing the redundant second check and moving the first check
> into a combined check with the result from the olpc_ofw call.
>
> Detected by cppcheck:
> Identical condition '(s32)node==-1', second condition is always false
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   arch/x86/platform/olpc/olpc_dt.c | 5 +----
>   1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
> index b4ab779f1d47..658363ec3ff3 100644
> --- a/arch/x86/platform/olpc/olpc_dt.c
> +++ b/arch/x86/platform/olpc/olpc_dt.c
> @@ -28,10 +28,7 @@ static phandle __init olpc_dt_getsibling(phandle node)
>   	const void *args[] = { (void *)node };
>   	void *res[] = { &node };
>   
> -	if ((s32)node == -1)
> -		return 0;
> -
> -	if (olpc_ofw("peer", args, res) || (s32)node == -1)
> +	if (((s32)node == -1) || olpc_ofw("peer", args, res))
>   		return 0;
>   
>   	return node;

'res' is { &node }

Could 'node' be modified by 'olpc_ofw(..., res)' and set to -1?

In other words, I'm not sure that the 2nd check is a redundant here.

Just my 2c,

CJ


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

* NACK: [PATCH] x86/platform/olpc: remove duplicated check on node == -1
  2018-12-09 17:13 ` Christophe JAILLET
@ 2018-12-09 17:30   ` Colin Ian King
  0 siblings, 0 replies; 4+ messages in thread
From: Colin Ian King @ 2018-12-09 17:30 UTC (permalink / raw)
  To: Christophe JAILLET, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, H . Peter Anvin, x86, Andrew Morton
  Cc: kernel-janitors, linux-kernel

On 09/12/2018 17:13, Christophe JAILLET wrote:
> Le 09/12/2018 à 16:01, Colin King a écrit :
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Currently the node == -1 check is being performed twice, the
>> second check is redundant and can be removed.  Fix this by
>> removing the redundant second check and moving the first check
>> into a combined check with the result from the olpc_ofw call.
>>
>> Detected by cppcheck:
>> Identical condition '(s32)node==-1', second condition is always false
>>
>> Signed-off-by: Colin Ian King <colin.king@canonical.com>
>> ---
>>   arch/x86/platform/olpc/olpc_dt.c | 5 +----
>>   1 file changed, 1 insertion(+), 4 deletions(-)
>>
>> diff --git a/arch/x86/platform/olpc/olpc_dt.c
>> b/arch/x86/platform/olpc/olpc_dt.c
>> index b4ab779f1d47..658363ec3ff3 100644
>> --- a/arch/x86/platform/olpc/olpc_dt.c
>> +++ b/arch/x86/platform/olpc/olpc_dt.c
>> @@ -28,10 +28,7 @@ static phandle __init olpc_dt_getsibling(phandle node)
>>       const void *args[] = { (void *)node };
>>       void *res[] = { &node };
>>   -    if ((s32)node == -1)
>> -        return 0;
>> -
>> -    if (olpc_ofw("peer", args, res) || (s32)node == -1)
>> +    if (((s32)node == -1) || olpc_ofw("peer", args, res))
>>           return 0;
>>         return node;
> 
> 'res' is { &node }
> 
> Could 'node' be modified by 'olpc_ofw(..., res)' and set to -1?
> 
> In other words, I'm not sure that the 2nd check is a redundant here.

Quite right. My mistake. Urgh.

> 
> Just my 2c,
> 
> CJ
> 


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

end of thread, other threads:[~2018-12-09 17:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-09 15:01 [PATCH] x86/platform/olpc: remove duplicated check on node == -1 Colin King
2018-12-09 17:10 ` Christophe JAILLET
2018-12-09 17:13 ` Christophe JAILLET
2018-12-09 17:30   ` NACK: " Colin Ian King

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®