scripts: checkpatch: allow case x: return #x macros
PATCH 1/1 scripts: checkpatch: allow case x: return #x macros
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.
--- scripts/checkpatch.pl | 1 + 1 file changed, 1 insertion(+)
scripts/checkpatch.pl +1 -0
@@ -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 (...)
Signature · 1 line
2.25.4
Joe Perches
maintainerQuoted 20 lines · Stanislaw Gruszka
Do not report errors like below:
./scripts/checkpatch.pl-fdrivers/net/wireless/ath/ath10k/wmi.hERROR: 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 <[email protected]>--- scripts/checkpatch.pl | 1 + 1 file changed, 1 insertion(+)scripts/checkpatch.pl +0
-0
scripts/checkpatch.pl sub process { · line 5904
Quoted 4 lines
scripts/checkpatch.pl +1
-0@@ -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'
Quoted 28 lines · Joe Perches
Quoted 20 lines · Stanislaw Gruszka
Do not report errors like below:
./scripts/checkpatch.pl-fdrivers/net/wireless/ath/ath10k/wmi.hERROR: 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 <[email protected]>--- scripts/checkpatch.pl | 1 + 1 file changed, 1 insertion(+)scripts/checkpatch.pl +0
-0scripts/checkpatch.pl sub process { · line 5904
Quoted 4 lines
scripts/checkpatch.pl +1
-0@@ -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 #xI think there needs to be a \s+ not \s* after return
Quoted 7 lines
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