scripts: checkpatch: allow case x: return #x macros

Message ID 20221027104934.160513-1-stf_xl@wp.pl
State New
Headers
Series scripts: checkpatch: allow case x: return #x macros |

Commit Message

Stanislaw Gruszka Oct. 27, 2022, 10:49 a.m. UTC
  Do not report errors like below:

./scripts/checkpatch.pl -f drivers/net/wireless/ath/ath10k/wmi.h

ERROR: Macros with complex values should be enclosed in parentheses
+#define C2S(x) case x: return #x

since "case x: return #x" macros are already used by some
in-kernel drivers.

Signed-off-by: Stanislaw Gruszka <stf_xl@wp.pl>
---
 scripts/checkpatch.pl | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Joe Perches Oct. 27, 2022, 11:15 a.m. UTC | #1
On Thu, 2022-10-27 at 12:49 +0200, Stanislaw Gruszka wrote:
> Do not report errors like below:
> 
> ./scripts/checkpatch.pl -f drivers/net/wireless/ath/ath10k/wmi.h
> 
> ERROR: Macros with complex values should be enclosed in parentheses
> +#define C2S(x) case x: return #x
> 
> since "case x: return #x" macros are already used by some
> in-kernel drivers.
> 
> Signed-off-by: Stanislaw Gruszka <stf_xl@wp.pl>
> ---
>  scripts/checkpatch.pl | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 1e5e66ae5a52..4b888b1313d5 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -5901,6 +5901,7 @@ sub process {
>  			    $dstat !~ /$exceptions/ &&
>  			    $dstat !~ /^\.$Ident\s*=/ &&				# .foo =
>  			    $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ &&		# stringification #foo
> +			    $dstat !~ /^case\s*$Ident:\s*return\s*#$Ident$/ &&		# case x: return #x

I think there needs to be a \s+ not \s* after return

And try this grep and see how many of these are handled

$ git grep -P -n '^\s*#\s*define.*\bcase.*#'

It may be better to just use

			    $dstat !~ /^case\b/ &&

$ git grep -P -n '^\s*#\s*define\s+\w+\([^\)]+\)\s*case\b'
  
Stanislaw Gruszka Oct. 27, 2022, 1:38 p.m. UTC | #2
On Thu, Oct 27, 2022 at 04:15:53AM -0700, Joe Perches wrote:
> On Thu, 2022-10-27 at 12:49 +0200, Stanislaw Gruszka wrote:
> > Do not report errors like below:
> > 
> > ./scripts/checkpatch.pl -f drivers/net/wireless/ath/ath10k/wmi.h
> > 
> > ERROR: Macros with complex values should be enclosed in parentheses
> > +#define C2S(x) case x: return #x
> > 
> > since "case x: return #x" macros are already used by some
> > in-kernel drivers.
> > 
> > Signed-off-by: Stanislaw Gruszka <stf_xl@wp.pl>
> > ---
> >  scripts/checkpatch.pl | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> > index 1e5e66ae5a52..4b888b1313d5 100755
> > --- a/scripts/checkpatch.pl
> > +++ b/scripts/checkpatch.pl
> > @@ -5901,6 +5901,7 @@ sub process {
> >  			    $dstat !~ /$exceptions/ &&
> >  			    $dstat !~ /^\.$Ident\s*=/ &&				# .foo =
> >  			    $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ &&		# stringification #foo
> > +			    $dstat !~ /^case\s*$Ident:\s*return\s*#$Ident$/ &&		# case x: return #x
> 
> I think there needs to be a \s+ not \s* after return
> 
> And try this grep and see how many of these are handled
> 
> $ git grep -P -n '^\s*#\s*define.*\bcase.*#'
> 
> It may be better to just use
> 
> 			    $dstat !~ /^case\b/ &&

Make sense, I'll send v2.

Thanks
Stanislaw
  

Patch

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 1e5e66ae5a52..4b888b1313d5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -5901,6 +5901,7 @@  sub process {
 			    $dstat !~ /$exceptions/ &&
 			    $dstat !~ /^\.$Ident\s*=/ &&				# .foo =
 			    $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ &&		# stringification #foo
+			    $dstat !~ /^case\s*$Ident:\s*return\s*#$Ident$/ &&		# case x: return #x
 			    $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ &&	# do {...} while (...); // do {...} while (...)
 			    $dstat !~ /^while\s*$Constant\s*$Constant\s*$/ &&		# while (...) {...}
 			    $dstat !~ /^for\s*$Constant$/ &&				# for (...)