linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] coccicheck: return proper error code on check fail
@ 2018-08-10 13:36 efremov
  2018-08-10 13:42 ` Julia Lawall
  2018-08-10 20:25 ` [PATCH v2] coccicheck: return proper error code on fail efremov
  0 siblings, 2 replies; 9+ messages in thread
From: efremov @ 2018-08-10 13:36 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Masahiro Yamada, Luis R . Rodriguez, Nicolas Palix,
	Gilles Muller, Michal Marek, linux-kernel, ldv-project,
	Denis Efremov

If coccicheck finds errors, it should return an error code
distinct from zero. Current code instead of exiting with an
error code of coccinelle returns error code of
'echo "coccicheck failed"' which is almost always equals to zero,
thus failing original intention of alerting about errors.
This patch fixes the problem.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Denis Efremov <efremov@linux.com>
---
 scripts/coccicheck | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/scripts/coccicheck b/scripts/coccicheck
index 9fedca611b7f..e04d328210ac 100755
--- a/scripts/coccicheck
+++ b/scripts/coccicheck
@@ -128,9 +128,10 @@ run_cmd_parmap() {
 	fi
 	echo $@ >>$DEBUG_FILE
 	$@ 2>>$DEBUG_FILE
-	if [[ $? -ne 0 ]]; then
+	err=$?
+	if [[ $err -ne 0 ]]; then
 		echo "coccicheck failed"
-		exit $?
+		exit $err
 	fi
 }
 
-- 
2.17.1


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

* Re: [PATCH] coccicheck: return proper error code on check fail
  2018-08-10 13:36 [PATCH] coccicheck: return proper error code on check fail efremov
@ 2018-08-10 13:42 ` Julia Lawall
  2018-08-10 14:20   ` Denis Efremov
  2018-08-10 20:25 ` [PATCH v2] coccicheck: return proper error code on fail efremov
  1 sibling, 1 reply; 9+ messages in thread
From: Julia Lawall @ 2018-08-10 13:42 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Masahiro Yamada, Luis R . Rodriguez, Nicolas Palix,
	Gilles Muller, Michal Marek, linux-kernel, ldv-project



On Fri, 10 Aug 2018, efremov@linux.com wrote:

> If coccicheck finds errors,

What do you mean by finds errors?  Do you mean that there is an error in
the behavior of coccicheck or that coccicheck finds an error in the source
code?

To put it another way, can you give an example of the kind of error you
are concerned about?

thanks,
julia

> it should return an error code
> distinct from zero. Current code instead of exiting with an
> error code of coccinelle returns error code of
> 'echo "coccicheck failed"' which is almost always equals to zero,
> thus failing original intention of alerting about errors.
> This patch fixes the problem.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Denis Efremov <efremov@linux.com>
> ---
>  scripts/coccicheck | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/coccicheck b/scripts/coccicheck
> index 9fedca611b7f..e04d328210ac 100755
> --- a/scripts/coccicheck
> +++ b/scripts/coccicheck
> @@ -128,9 +128,10 @@ run_cmd_parmap() {
>  	fi
>  	echo $@ >>$DEBUG_FILE
>  	$@ 2>>$DEBUG_FILE
> -	if [[ $? -ne 0 ]]; then
> +	err=$?
> +	if [[ $err -ne 0 ]]; then
>  		echo "coccicheck failed"
> -		exit $?
> +		exit $err
>  	fi
>  }
>
> --
> 2.17.1
>
>

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

* Re: [PATCH] coccicheck: return proper error code on check fail
  2018-08-10 13:42 ` Julia Lawall
@ 2018-08-10 14:20   ` Denis Efremov
  2018-08-10 14:28     ` Julia Lawall
  0 siblings, 1 reply; 9+ messages in thread
From: Denis Efremov @ 2018-08-10 14:20 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Masahiro Yamada, Luis R . Rodriguez, Nicolas Palix,
	Gilles Muller, Michal Marek, linux-kernel, ldv-project

> Do you mean that there is an error in the behavior of coccicheck or that coccicheck finds an error in the source code?

An error in the source code.

Here is an example of how the patch changes the behavior of 'make
coccicheck' (my comments after the ###):
Current behavior:
$ make M=mymodule coccicheck
mymodule/file1.c:97:4-14: ERROR: Assignment of bool to non-0/1 constant
mymodule/file2.c:104:4-19: ERROR: Assignment of bool to non-0/1 constant
mymodule/file2.c:577:1-15: code aligned with following code on line 583
mymodule/file3.c:439:5-10: Unneeded variable: "error". Return "0" on line 449
mymodule/file4.c:451:5-7: Unneeded variable: "rc". Return "0" on line 455
mymodule/file5.c:433:5-8: Unneeded variable: "ret". Return "0" on line 607
mymodule/file6.c:433:5-10: Unneeded variable: "error". Return "0" on line 440
mymodule/file7.c:774:2-3: Unneeded semicolon
coccicheck failed     ### <-- Check failed
$ echo $?
0 ### <-- But error code signals that everthing is OK

After this patch:
$ make M=mymodule coccicheck
...
coccicheck failed
make: *** [Makefile:1636: coccicheck] Error 2
$ echo $?
2 ### <-- The patch changes error code

Why does this matter?
1) Because it's clear from the source code that the original intention
was to return an error code of checking command, not the "echo
'coccicheck failed'" command.
2) Automated testing systems (CI, for example) rely on the return code.

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

* Re: [PATCH] coccicheck: return proper error code on check fail
  2018-08-10 14:20   ` Denis Efremov
@ 2018-08-10 14:28     ` Julia Lawall
  2018-08-10 14:45       ` Denis Efremov
  0 siblings, 1 reply; 9+ messages in thread
From: Julia Lawall @ 2018-08-10 14:28 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Masahiro Yamada, Luis R . Rodriguez, Nicolas Palix,
	Gilles Muller, Michal Marek, linux-kernel, ldv-project



On Fri, 10 Aug 2018, Denis Efremov wrote:

> > Do you mean that there is an error in the behavior of coccicheck or that coccicheck finds an error in the source code?
>
> An error in the source code.
>
> Here is an example of how the patch changes the behavior of 'make
> coccicheck' (my comments after the ###):
> Current behavior:
> $ make M=mymodule coccicheck
> mymodule/file1.c:97:4-14: ERROR: Assignment of bool to non-0/1 constant
> mymodule/file2.c:104:4-19: ERROR: Assignment of bool to non-0/1 constant
> mymodule/file2.c:577:1-15: code aligned with following code on line 583
> mymodule/file3.c:439:5-10: Unneeded variable: "error". Return "0" on line 449
> mymodule/file4.c:451:5-7: Unneeded variable: "rc". Return "0" on line 455
> mymodule/file5.c:433:5-8: Unneeded variable: "ret". Return "0" on line 607
> mymodule/file6.c:433:5-10: Unneeded variable: "error". Return "0" on line 440
> mymodule/file7.c:774:2-3: Unneeded semicolon
> coccicheck failed     ### <-- Check failed

Are you sure that this coccicheck failed has any connection to the various
messages printed above it?  Normally Coccinelle has no idea about the
semantics of messages printed using python script code.  I'm not sure what
would cause it to return an error code because a particular script was
activated.

julia

> $ echo $?
> 0 ### <-- But error code signals that everthing is OK
>
> After this patch:
> $ make M=mymodule coccicheck
> ...
> coccicheck failed
> make: *** [Makefile:1636: coccicheck] Error 2
> $ echo $?
> 2 ### <-- The patch changes error code
>
> Why does this matter?
> 1) Because it's clear from the source code that the original intention
> was to return an error code of checking command, not the "echo
> 'coccicheck failed'" command.
> 2) Automated testing systems (CI, for example) rely on the return code.
>

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

* Re: [PATCH] coccicheck: return proper error code on check fail
  2018-08-10 14:28     ` Julia Lawall
@ 2018-08-10 14:45       ` Denis Efremov
  2018-08-10 18:23         ` Himanshu Jha
  0 siblings, 1 reply; 9+ messages in thread
From: Denis Efremov @ 2018-08-10 14:45 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Masahiro Yamada, Luis R . Rodriguez, Nicolas Palix,
	Gilles Muller, Michal Marek, linux-kernel, ldv-project

My mistake. Initially, I thought that this line signals about errors
in the code, but now I see that this is about the tool's internal
error. However, this doesn't change the fact that coccicheck returns
the improper error code.

I will reformulate the commit message and send the v2 patch with the
same diff. Thank you for clarifying things.

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

* Re: [PATCH] coccicheck: return proper error code on check fail
  2018-08-10 14:45       ` Denis Efremov
@ 2018-08-10 18:23         ` Himanshu Jha
  0 siblings, 0 replies; 9+ messages in thread
From: Himanshu Jha @ 2018-08-10 18:23 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Julia Lawall, Masahiro Yamada, Luis R . Rodriguez, Nicolas Palix,
	Gilles Muller, Michal Marek, linux-kernel, ldv-project

On Fri, Aug 10, 2018 at 05:45:46PM +0300, Denis Efremov wrote:
> My mistake. Initially, I thought that this line signals about errors
> in the code, but now I see that this is about the tool's internal
> error. However, this doesn't change the fact that coccicheck returns
> the improper error code.
> 
> I will reformulate the commit message and send the v2 patch with the
> same diff. Thank you for clarifying things.

I would also request to use the latest source from 
https://github.com/coccinelle/coccinelle

Because some distribution supplied coccinelle packages are
obsolete and likely more prone to be disfunctional.

For instance: https://systeme.lip6.fr/pipermail/cocci/2017-December/004799.html

Thanks.
-- 
Himanshu Jha
Undergraduate Student
Department of Electronics & Communication
Guru Tegh Bahadur Institute of Technology

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

* [PATCH v2] coccicheck: return proper error code on fail
  2018-08-10 13:36 [PATCH] coccicheck: return proper error code on check fail efremov
  2018-08-10 13:42 ` Julia Lawall
@ 2018-08-10 20:25 ` efremov
  2018-08-10 20:31   ` Julia Lawall
  1 sibling, 1 reply; 9+ messages in thread
From: efremov @ 2018-08-10 20:25 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Denis Efremov, Masahiro Yamada, Luis R . Rodriguez,
	Nicolas Palix, Gilles Muller, Michal Marek, linux-kernel,
	ldv-project

From: Denis Efremov <efremov@linux.com>

If coccicheck fails, it should return an error code distinct from zero
to signal about an internal problem. Current code instead of exiting with
the tool's error code returns the error code of 'echo "coccicheck failed"'
which is almost always equals to zero, thus failing the original intention
of alerting about a problem. This patch fixes the code.

Found by Linux Driver Verification project (linuxtesting.org).

Signed-off-by: Denis Efremov <efremov@linux.com>
---
 scripts/coccicheck | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/scripts/coccicheck b/scripts/coccicheck
index 9fedca611b7f..e04d328210ac 100755
--- a/scripts/coccicheck
+++ b/scripts/coccicheck
@@ -128,9 +128,10 @@ run_cmd_parmap() {
 	fi
 	echo $@ >>$DEBUG_FILE
 	$@ 2>>$DEBUG_FILE
-	if [[ $? -ne 0 ]]; then
+	err=$?
+	if [[ $err -ne 0 ]]; then
 		echo "coccicheck failed"
-		exit $?
+		exit $err
 	fi
 }
 
-- 
2.17.1


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

* Re: [PATCH v2] coccicheck: return proper error code on fail
  2018-08-10 20:25 ` [PATCH v2] coccicheck: return proper error code on fail efremov
@ 2018-08-10 20:31   ` Julia Lawall
  2018-08-13  7:28     ` Masahiro Yamada
  0 siblings, 1 reply; 9+ messages in thread
From: Julia Lawall @ 2018-08-10 20:31 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Masahiro Yamada, Luis R . Rodriguez, Nicolas Palix,
	Gilles Muller, Michal Marek, linux-kernel, ldv-project



On Fri, 10 Aug 2018, efremov@linux.com wrote:

> From: Denis Efremov <efremov@linux.com>
>
> If coccicheck fails, it should return an error code distinct from zero
> to signal about an internal problem. Current code instead of exiting with
> the tool's error code returns the error code of 'echo "coccicheck failed"'
> which is almost always equals to zero, thus failing the original intention
> of alerting about a problem. This patch fixes the code.
>
> Found by Linux Driver Verification project (linuxtesting.org).
>
> Signed-off-by: Denis Efremov <efremov@linux.com>

OK, I get it now.  Thanks.

Acked-by: Julia Lawall <julia.lawall@lip6.fr>

> ---
>  scripts/coccicheck | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/coccicheck b/scripts/coccicheck
> index 9fedca611b7f..e04d328210ac 100755
> --- a/scripts/coccicheck
> +++ b/scripts/coccicheck
> @@ -128,9 +128,10 @@ run_cmd_parmap() {
>  	fi
>  	echo $@ >>$DEBUG_FILE
>  	$@ 2>>$DEBUG_FILE
> -	if [[ $? -ne 0 ]]; then
> +	err=$?
> +	if [[ $err -ne 0 ]]; then
>  		echo "coccicheck failed"
> -		exit $?
> +		exit $err
>  	fi
>  }
>
> --
> 2.17.1
>
>

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

* Re: [PATCH v2] coccicheck: return proper error code on fail
  2018-08-10 20:31   ` Julia Lawall
@ 2018-08-13  7:28     ` Masahiro Yamada
  0 siblings, 0 replies; 9+ messages in thread
From: Masahiro Yamada @ 2018-08-13  7:28 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Denis Efremov, Luis R . Rodriguez, Nicolas Palix, Gilles Muller,
	Michal Marek, Linux Kernel Mailing List, ldv-project

2018-08-11 5:31 GMT+09:00 Julia Lawall <julia.lawall@lip6.fr>:
>
>
> On Fri, 10 Aug 2018, efremov@linux.com wrote:
>
>> From: Denis Efremov <efremov@linux.com>
>>
>> If coccicheck fails, it should return an error code distinct from zero
>> to signal about an internal problem. Current code instead of exiting with
>> the tool's error code returns the error code of 'echo "coccicheck failed"'
>> which is almost always equals to zero, thus failing the original intention
>> of alerting about a problem. This patch fixes the code.
>>
>> Found by Linux Driver Verification project (linuxtesting.org).
>>
>> Signed-off-by: Denis Efremov <efremov@linux.com>
>
> OK, I get it now.  Thanks.
>
> Acked-by: Julia Lawall <julia.lawall@lip6.fr>
>


Applied to linux-kbuild. Thanks!


>> ---
>>  scripts/coccicheck | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>>
>> diff --git a/scripts/coccicheck b/scripts/coccicheck
>> index 9fedca611b7f..e04d328210ac 100755
>> --- a/scripts/coccicheck
>> +++ b/scripts/coccicheck
>> @@ -128,9 +128,10 @@ run_cmd_parmap() {
>>       fi
>>       echo $@ >>$DEBUG_FILE
>>       $@ 2>>$DEBUG_FILE
>> -     if [[ $? -ne 0 ]]; then
>> +     err=$?
>> +     if [[ $err -ne 0 ]]; then
>>               echo "coccicheck failed"
>> -             exit $?
>> +             exit $err
>>       fi
>>  }
>>
>> --
>> 2.17.1
>>
>>



-- 
Best Regards
Masahiro Yamada

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

end of thread, other threads:[~2018-08-13  7:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-10 13:36 [PATCH] coccicheck: return proper error code on check fail efremov
2018-08-10 13:42 ` Julia Lawall
2018-08-10 14:20   ` Denis Efremov
2018-08-10 14:28     ` Julia Lawall
2018-08-10 14:45       ` Denis Efremov
2018-08-10 18:23         ` Himanshu Jha
2018-08-10 20:25 ` [PATCH v2] coccicheck: return proper error code on fail efremov
2018-08-10 20:31   ` Julia Lawall
2018-08-13  7:28     ` Masahiro Yamada

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).