All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mnt: remove unneeded conversion to bool
@ 2021-11-25  0:56 davidcomponentone
  2021-12-03 18:26 ` Shuah Khan
  0 siblings, 1 reply; 6+ messages in thread
From: davidcomponentone @ 2021-11-25  0:56 UTC (permalink / raw)
  To: shuah
  Cc: davidcomponentone, linux-kselftest, linux-kernel, Yang Guang, Zeal Robot

From: Yang Guang <yang.guang5@zte.com.cn>

The coccinelle report
./tools/testing/selftests/mount/unprivileged-remount-test.c:285:54-59:
WARNING: conversion to bool not needed here
./tools/testing/selftests/mount/unprivileged-remount-test.c:207:54-59:
WARNING: conversion to bool not needed here
Relational and logical operators evaluate to bool,
explicit conversion is overly verbose and unneeded.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
---
 tools/testing/selftests/mount/unprivileged-remount-test.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/mount/unprivileged-remount-test.c b/tools/testing/selftests/mount/unprivileged-remount-test.c
index 584dc6bc3b06..d2917054fe3a 100644
--- a/tools/testing/selftests/mount/unprivileged-remount-test.c
+++ b/tools/testing/selftests/mount/unprivileged-remount-test.c
@@ -204,7 +204,7 @@ bool test_unpriv_remount(const char *fstype, const char *mount_options,
 		if (!WIFEXITED(status)) {
 			die("child did not terminate cleanly\n");
 		}
-		return WEXITSTATUS(status) == EXIT_SUCCESS ? true : false;
+		return WEXITSTATUS(status) == EXIT_SUCCESS;
 	}
 
 	create_and_enter_userns();
@@ -282,7 +282,7 @@ static bool test_priv_mount_unpriv_remount(void)
 		if (!WIFEXITED(status)) {
 			die("child did not terminate cleanly\n");
 		}
-		return WEXITSTATUS(status) == EXIT_SUCCESS ? true : false;
+		return WEXITSTATUS(status) == EXIT_SUCCESS;
 	}
 
 	orig_mnt_flags = read_mnt_flags(orig_path);
-- 
2.30.2


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

* Re: [PATCH] mnt: remove unneeded conversion to bool
  2021-11-25  0:56 [PATCH] mnt: remove unneeded conversion to bool davidcomponentone
@ 2021-12-03 18:26 ` Shuah Khan
  2021-12-03 19:50   ` Joe Perches
  0 siblings, 1 reply; 6+ messages in thread
From: Shuah Khan @ 2021-12-03 18:26 UTC (permalink / raw)
  To: davidcomponentone, shuah
  Cc: linux-kselftest, linux-kernel, Yang Guang, Zeal Robot, Shuah Khan

On 11/24/21 5:56 PM, davidcomponentone@gmail.com wrote:
> From: Yang Guang <yang.guang5@zte.com.cn>
> 
> The coccinelle report
> ./tools/testing/selftests/mount/unprivileged-remount-test.c:285:54-59:
> WARNING: conversion to bool not needed here
> ./tools/testing/selftests/mount/unprivileged-remount-test.c:207:54-59:
> WARNING: conversion to bool not needed here
> Relational and logical operators evaluate to bool,
> explicit conversion is overly verbose and unneeded.
> 
> Reported-by: Zeal Robot <zealci@zte.com.cn>
> Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
> ---
>   tools/testing/selftests/mount/unprivileged-remount-test.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/mount/unprivileged-remount-test.c b/tools/testing/selftests/mount/unprivileged-remount-test.c
> index 584dc6bc3b06..d2917054fe3a 100644
> --- a/tools/testing/selftests/mount/unprivileged-remount-test.c
> +++ b/tools/testing/selftests/mount/unprivileged-remount-test.c
> @@ -204,7 +204,7 @@ bool test_unpriv_remount(const char *fstype, const char *mount_options,
>   		if (!WIFEXITED(status)) {
>   			die("child did not terminate cleanly\n");
>   		}
> -		return WEXITSTATUS(status) == EXIT_SUCCESS ? true : false;
> +		return WEXITSTATUS(status) == EXIT_SUCCESS;
>   	}
>   
>   	create_and_enter_userns();
> @@ -282,7 +282,7 @@ static bool test_priv_mount_unpriv_remount(void)
>   		if (!WIFEXITED(status)) {
>   			die("child did not terminate cleanly\n");
>   		}
> -		return WEXITSTATUS(status) == EXIT_SUCCESS ? true : false;
> +		return WEXITSTATUS(status) == EXIT_SUCCESS;
>   	}
>   
>   	orig_mnt_flags = read_mnt_flags(orig_path);
> 

This change doesn't look right. WEXITSTATUS(status) return could be
> 1 or 0 or negative.

thanks,
-- Shuah

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

* Re: [PATCH] mnt: remove unneeded conversion to bool
  2021-12-03 18:26 ` Shuah Khan
@ 2021-12-03 19:50   ` Joe Perches
  2021-12-04  0:24     ` Shuah Khan
  0 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2021-12-03 19:50 UTC (permalink / raw)
  To: Shuah Khan, davidcomponentone, shuah
  Cc: linux-kselftest, linux-kernel, Yang Guang, Zeal Robot

On Fri, 2021-12-03 at 11:26 -0700, Shuah Khan wrote:
> On 11/24/21 5:56 PM, davidcomponentone@gmail.com wrote:
> > From: Yang Guang <yang.guang5@zte.com.cn>
> > 
> > The coccinelle report
> > ./tools/testing/selftests/mount/unprivileged-remount-test.c:285:54-59:
> > WARNING: conversion to bool not needed here
> > ./tools/testing/selftests/mount/unprivileged-remount-test.c:207:54-59:
> > WARNING: conversion to bool not needed here
> > Relational and logical operators evaluate to bool,
> > explicit conversion is overly verbose and unneeded.
> > 
> > Reported-by: Zeal Robot <zealci@zte.com.cn>
> > Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
> > ---
> >   tools/testing/selftests/mount/unprivileged-remount-test.c | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/mount/unprivileged-remount-test.c b/tools/testing/selftests/mount/unprivileged-remount-test.c
> > index 584dc6bc3b06..d2917054fe3a 100644
> > --- a/tools/testing/selftests/mount/unprivileged-remount-test.c
> > +++ b/tools/testing/selftests/mount/unprivileged-remount-test.c
> > @@ -204,7 +204,7 @@ bool test_unpriv_remount(const char *fstype, const char *mount_options,
> >   		if (!WIFEXITED(status)) {
> >   			die("child did not terminate cleanly\n");
> >   		}
> > -		return WEXITSTATUS(status) == EXIT_SUCCESS ? true : false;
> > +		return WEXITSTATUS(status) == EXIT_SUCCESS;
> >   	}
> >   
> >   	create_and_enter_userns();
> > @@ -282,7 +282,7 @@ static bool test_priv_mount_unpriv_remount(void)
> >   		if (!WIFEXITED(status)) {
> >   			die("child did not terminate cleanly\n");
> >   		}
> > -		return WEXITSTATUS(status) == EXIT_SUCCESS ? true : false;
> > +		return WEXITSTATUS(status) == EXIT_SUCCESS;
> >   	}
> >   
> >   	orig_mnt_flags = read_mnt_flags(orig_path);
> > 
> 
> This change doesn't look right. WEXITSTATUS(status) return could be
> > 1 or 0 or negative.

The change is at least logically correct.

And isn't WEXITSTATUS range limited from 0->255 ?

https://www.gnu.org/software/libc/manual/html_node/Exit-Status.html



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

* Re: [PATCH] mnt: remove unneeded conversion to bool
  2021-12-03 19:50   ` Joe Perches
@ 2021-12-04  0:24     ` Shuah Khan
  2021-12-04  3:06       ` Joe Perches
  0 siblings, 1 reply; 6+ messages in thread
From: Shuah Khan @ 2021-12-04  0:24 UTC (permalink / raw)
  To: Joe Perches, davidcomponentone, shuah
  Cc: linux-kselftest, linux-kernel, Yang Guang, Zeal Robot, Shuah Khan

On 12/3/21 12:50 PM, Joe Perches wrote:
> On Fri, 2021-12-03 at 11:26 -0700, Shuah Khan wrote:
>> On 11/24/21 5:56 PM, davidcomponentone@gmail.com wrote:
>>> From: Yang Guang <yang.guang5@zte.com.cn>
>>>
>>> The coccinelle report
>>> ./tools/testing/selftests/mount/unprivileged-remount-test.c:285:54-59:
>>> WARNING: conversion to bool not needed here
>>> ./tools/testing/selftests/mount/unprivileged-remount-test.c:207:54-59:
>>> WARNING: conversion to bool not needed here
>>> Relational and logical operators evaluate to bool,
>>> explicit conversion is overly verbose and unneeded.
>>>
>>> Reported-by: Zeal Robot <zealci@zte.com.cn>
>>> Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
>>> ---
>>>    tools/testing/selftests/mount/unprivileged-remount-test.c | 4 ++--
>>>    1 file changed, 2 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/tools/testing/selftests/mount/unprivileged-remount-test.c b/tools/testing/selftests/mount/unprivileged-remount-test.c
>>> index 584dc6bc3b06..d2917054fe3a 100644
>>> --- a/tools/testing/selftests/mount/unprivileged-remount-test.c
>>> +++ b/tools/testing/selftests/mount/unprivileged-remount-test.c
>>> @@ -204,7 +204,7 @@ bool test_unpriv_remount(const char *fstype, const char *mount_options,
>>>    		if (!WIFEXITED(status)) {
>>>    			die("child did not terminate cleanly\n");
>>>    		}
>>> -		return WEXITSTATUS(status) == EXIT_SUCCESS ? true : false;
>>> +		return WEXITSTATUS(status) == EXIT_SUCCESS;
>>>    	}
>>>    
>>>    	create_and_enter_userns();
>>> @@ -282,7 +282,7 @@ static bool test_priv_mount_unpriv_remount(void)
>>>    		if (!WIFEXITED(status)) {
>>>    			die("child did not terminate cleanly\n");
>>>    		}
>>> -		return WEXITSTATUS(status) == EXIT_SUCCESS ? true : false;
>>> +		return WEXITSTATUS(status) == EXIT_SUCCESS;
>>>    	}
>>>    
>>>    	orig_mnt_flags = read_mnt_flags(orig_path);
>>>
>>
>> This change doesn't look right. WEXITSTATUS(status) return could be
>>> 1 or 0 or negative.
> 
> The change is at least logically correct.
> 
> And isn't WEXITSTATUS range limited from 0->255 ?
> 
> https://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
> 

You are right. In any case, I don't see any value in changing the current
logic. The way it is coded is cryptic enough :)

thanks,
-- Shuah

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

* Re: [PATCH] mnt: remove unneeded conversion to bool
  2021-12-04  0:24     ` Shuah Khan
@ 2021-12-04  3:06       ` Joe Perches
  2021-12-06 19:00         ` Shuah Khan
  0 siblings, 1 reply; 6+ messages in thread
From: Joe Perches @ 2021-12-04  3:06 UTC (permalink / raw)
  To: Shuah Khan, davidcomponentone, shuah
  Cc: linux-kselftest, linux-kernel, Yang Guang, Zeal Robot

On Fri, 2021-12-03 at 17:24 -0700, Shuah Khan wrote:
> On 12/3/21 12:50 PM, Joe Perches wrote:
> > On Fri, 2021-12-03 at 11:26 -0700, Shuah Khan wrote:
> > > On 11/24/21 5:56 PM, davidcomponentone@gmail.com wrote:
> > > > From: Yang Guang <yang.guang5@zte.com.cn>
> > > > 
> > > > The coccinelle report
> > > > ./tools/testing/selftests/mount/unprivileged-remount-test.c:285:54-59:
> > > > WARNING: conversion to bool not needed here
> > > > ./tools/testing/selftests/mount/unprivileged-remount-test.c:207:54-59:
> > > > WARNING: conversion to bool not needed here
> > > > Relational and logical operators evaluate to bool,
> > > > explicit conversion is overly verbose and unneeded.
> > > > 
> > > > Reported-by: Zeal Robot <zealci@zte.com.cn>
> > > > Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
> > > > ---
> > > >    tools/testing/selftests/mount/unprivileged-remount-test.c | 4 ++--
> > > >    1 file changed, 2 insertions(+), 2 deletions(-)
> > > > 
> > > > diff --git a/tools/testing/selftests/mount/unprivileged-remount-test.c b/tools/testing/selftests/mount/unprivileged-remount-test.c
> > > > index 584dc6bc3b06..d2917054fe3a 100644
> > > > --- a/tools/testing/selftests/mount/unprivileged-remount-test.c
> > > > +++ b/tools/testing/selftests/mount/unprivileged-remount-test.c
> > > > @@ -204,7 +204,7 @@ bool test_unpriv_remount(const char *fstype, const char *mount_options,
> > > >    		if (!WIFEXITED(status)) {
> > > >    			die("child did not terminate cleanly\n");
> > > >    		}
> > > > -		return WEXITSTATUS(status) == EXIT_SUCCESS ? true : false;
> > > > +		return WEXITSTATUS(status) == EXIT_SUCCESS;
> > > >    	}
> > > >    
> > > >    	create_and_enter_userns();
> > > > @@ -282,7 +282,7 @@ static bool test_priv_mount_unpriv_remount(void)
> > > >    		if (!WIFEXITED(status)) {
> > > >    			die("child did not terminate cleanly\n");
> > > >    		}
> > > > -		return WEXITSTATUS(status) == EXIT_SUCCESS ? true : false;
> > > > +		return WEXITSTATUS(status) == EXIT_SUCCESS;
> > > >    	}
> > > >    
> > > >    	orig_mnt_flags = read_mnt_flags(orig_path);
> > > > 
> > > 
> > > This change doesn't look right. WEXITSTATUS(status) return could be
> > > > 1 or 0 or negative.
> > 
> > The change is at least logically correct.
> > 
> > And isn't WEXITSTATUS range limited from 0->255 ?
> > 
> > https://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
> > 
> 
> You are right. In any case, I don't see any value in changing the current
> logic. The way it is coded is cryptic enough :)

Well, it'd be more like the rest of the kernel when changed.

bool function()
{
	...
	return <foo> ? true : false;
}

is pretty redundant.



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

* Re: [PATCH] mnt: remove unneeded conversion to bool
  2021-12-04  3:06       ` Joe Perches
@ 2021-12-06 19:00         ` Shuah Khan
  0 siblings, 0 replies; 6+ messages in thread
From: Shuah Khan @ 2021-12-06 19:00 UTC (permalink / raw)
  To: Joe Perches, davidcomponentone, shuah
  Cc: linux-kselftest, linux-kernel, Yang Guang, Zeal Robot, Shuah Khan

On 12/3/21 8:06 PM, Joe Perches wrote:
> On Fri, 2021-12-03 at 17:24 -0700, Shuah Khan wrote:
>> On 12/3/21 12:50 PM, Joe Perches wrote:
>>> On Fri, 2021-12-03 at 11:26 -0700, Shuah Khan wrote:
>>>> On 11/24/21 5:56 PM, davidcomponentone@gmail.com wrote:
>>>>> From: Yang Guang <yang.guang5@zte.com.cn>
>>>>>
>>>>> The coccinelle report
>>>>> ./tools/testing/selftests/mount/unprivileged-remount-test.c:285:54-59:
>>>>> WARNING: conversion to bool not needed here
>>>>> ./tools/testing/selftests/mount/unprivileged-remount-test.c:207:54-59:
>>>>> WARNING: conversion to bool not needed here
>>>>> Relational and logical operators evaluate to bool,
>>>>> explicit conversion is overly verbose and unneeded.
>>>>>
>>>>> Reported-by: Zeal Robot <zealci@zte.com.cn>
>>>>> Signed-off-by: Yang Guang <yang.guang5@zte.com.cn>
>>>>> ---
>>>>>     tools/testing/selftests/mount/unprivileged-remount-test.c | 4 ++--
>>>>>     1 file changed, 2 insertions(+), 2 deletions(-)
>>>>>
>>>>> diff --git a/tools/testing/selftests/mount/unprivileged-remount-test.c b/tools/testing/selftests/mount/unprivileged-remount-test.c
>>>>> index 584dc6bc3b06..d2917054fe3a 100644
>>>>> --- a/tools/testing/selftests/mount/unprivileged-remount-test.c
>>>>> +++ b/tools/testing/selftests/mount/unprivileged-remount-test.c
>>>>> @@ -204,7 +204,7 @@ bool test_unpriv_remount(const char *fstype, const char *mount_options,
>>>>>     		if (!WIFEXITED(status)) {
>>>>>     			die("child did not terminate cleanly\n");
>>>>>     		}
>>>>> -		return WEXITSTATUS(status) == EXIT_SUCCESS ? true : false;
>>>>> +		return WEXITSTATUS(status) == EXIT_SUCCESS;
>>>>>     	}
>>>>>     
>>>>>     	create_and_enter_userns();
>>>>> @@ -282,7 +282,7 @@ static bool test_priv_mount_unpriv_remount(void)
>>>>>     		if (!WIFEXITED(status)) {
>>>>>     			die("child did not terminate cleanly\n");
>>>>>     		}
>>>>> -		return WEXITSTATUS(status) == EXIT_SUCCESS ? true : false;
>>>>> +		return WEXITSTATUS(status) == EXIT_SUCCESS;
>>>>>     	}
>>>>>     
>>>>>     	orig_mnt_flags = read_mnt_flags(orig_path);
>>>>>
>>>>
>>>> This change doesn't look right. WEXITSTATUS(status) return could be
>>>>> 1 or 0 or negative.
>>>
>>> The change is at least logically correct.
>>>
>>> And isn't WEXITSTATUS range limited from 0->255 ?
>>>
>>> https://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
>>>
>>
>> You are right. In any case, I don't see any value in changing the current
>> logic. The way it is coded is cryptic enough :)
> 
> Well, it'd be more like the rest of the kernel when changed.
> 
> bool function()
> {
> 	...
> 	return <foo> ? true : false;
> }
> 
> is pretty redundant.
> 
> 

Fair enough.

Yang Guang,

Applied patch. In the future, make sure to use selftests/<test>: convention
for patch summary. I fixed this one for now.

thanks,
-- Shuah

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

end of thread, other threads:[~2021-12-06 19:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-25  0:56 [PATCH] mnt: remove unneeded conversion to bool davidcomponentone
2021-12-03 18:26 ` Shuah Khan
2021-12-03 19:50   ` Joe Perches
2021-12-04  0:24     ` Shuah Khan
2021-12-04  3:06       ` Joe Perches
2021-12-06 19:00         ` Shuah Khan

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.