public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] scripts/checkpatch.pl: avoid false warning missing break
@ 2017-09-10  7:52 Heinrich Schuchardt
  2017-09-10 14:16 ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Heinrich Schuchardt @ 2017-09-10  7:52 UTC (permalink / raw)
  To: Andy Whitcroft, Joe Perches; +Cc: linux-kernel, Heinrich Schuchardt

void foo(int a)
	switch (a) {
	case 'h':
		fun1();
		exit(1);
	default:
}

creates a warning
Possible switch case/default not preceded by break
or fallthrough comment

exit( should be treated like return.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 3afc870f0f..da09b2313c 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4361,7 +4361,7 @@ sub process {
 				next if ($fline =~ /^.[\s$;]*$/);
 				$has_statement = 1;
 				$count++;
-				$has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|return\b|goto\b|continue\b)/);
+				$has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|exit\(\b|return\b|goto\b|continue\b)/);
 			}
 			if (!$has_break && $has_statement) {
 				WARN("MISSING_BREAK",
-- 
2.11.0

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

* Re: [PATCH 1/1] scripts/checkpatch.pl: avoid false warning missing break
  2017-09-10  7:52 [PATCH 1/1] scripts/checkpatch.pl: avoid false warning missing break Heinrich Schuchardt
@ 2017-09-10 14:16 ` Joe Perches
  2017-09-10 15:46   ` [PATCH v2 " Heinrich Schuchardt
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2017-09-10 14:16 UTC (permalink / raw)
  To: Heinrich Schuchardt, Andy Whitcroft; +Cc: linux-kernel

On Sun, 2017-09-10 at 09:52 +0200, Heinrich Schuchardt wrote:
> void foo(int a)
> 	switch (a) {
> 	case 'h':
> 		fun1();
> 		exit(1);
> 	default:
> }
> 
> creates a warning
> Possible switch case/default not preceded by break
> or fallthrough comment
> 
> exit( should be treated like return.

OK, but

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -4361,7 +4361,7 @@ sub process {
>  				next if ($fline =~ /^.[\s$;]*$/);
>  				$has_statement = 1;
>  				$count++;
> -				$has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|return\b|goto\b|continue\b)/);
> +				$has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|exit\(\b|return\b|goto\b|continue\b)/);

exit\s*\(

Although this could have a false negative
on some code.

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

* [PATCH v2 1/1] scripts/checkpatch.pl: avoid false warning missing break
  2017-09-10 14:16 ` Joe Perches
@ 2017-09-10 15:46   ` Heinrich Schuchardt
  2017-09-10 17:55     ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Heinrich Schuchardt @ 2017-09-10 15:46 UTC (permalink / raw)
  To: Joe Perches; +Cc: Andy Whitcroft, linux-kernel, Heinrich Schuchardt

void foo(int a)
	switch (a) {
	case 'h':
		fun1();
		exit(1);
	default:
}

creates a warning
Possible switch case/default not preceded by break
or fallthrough comment

exit( should be treated like return.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
v2:
	Allow whitespace between 'exit' and '('.
---
 scripts/checkpatch.pl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2287a0bca8..690fe07d1b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6084,7 +6084,7 @@ sub process {
 				next if ($fline =~ /^.[\s$;]*$/);
 				$has_statement = 1;
 				$count++;
-				$has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|return\b|goto\b|continue\b)/);
+				$has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|exit\s*\(\b|return\b|goto\b|continue\b)/);
 			}
 			if (!$has_break && $has_statement) {
 				WARN("MISSING_BREAK",
-- 
2.11.0

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

* Re: [PATCH v2 1/1] scripts/checkpatch.pl: avoid false warning missing break
  2017-09-10 15:46   ` [PATCH v2 " Heinrich Schuchardt
@ 2017-09-10 17:55     ` Joe Perches
  0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2017-09-10 17:55 UTC (permalink / raw)
  To: Heinrich Schuchardt, Andrew Morton; +Cc: Andy Whitcroft, linux-kernel

On Sun, 2017-09-10 at 17:46 +0200, Heinrich Schuchardt wrote:
> void foo(int a)
> 	switch (a) {
> 	case 'h':
> 		fun1();
> 		exit(1);
> 	default:
> }
> 
> creates a warning
> Possible switch case/default not preceded by break
> or fallthrough comment
> 
> exit( should be treated like return.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>

Acked-by: Joe Perches <joe@perches.com>

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -6084,7 +6084,7 @@ sub process {
>  				next if ($fline =~ /^.[\s$;]*$/);
>  				$has_statement = 1;
>  				$count++;
> -				$has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|return\b|goto\b|continue\b)/);
> +				$has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|exit\s*\(\b|return\b|goto\b|continue\b)/);
>  			}
>  			if (!$has_break && $has_statement) {
>  				WARN("MISSING_BREAK",

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

end of thread, other threads:[~2017-09-10 17:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-10  7:52 [PATCH 1/1] scripts/checkpatch.pl: avoid false warning missing break Heinrich Schuchardt
2017-09-10 14:16 ` Joe Perches
2017-09-10 15:46   ` [PATCH v2 " Heinrich Schuchardt
2017-09-10 17:55     ` Joe Perches

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