Skip to contentSkip to conversation

checkpatch: allow multi-statement declarative macros.

PATCH In review Jim Cromie 2 participants 4 messages May 16, 2024 – May 17, 2024 Checkpatch

lore
Share & tools
lore

Jim Cromie

author
#0 lore raw

PATCH 1/1 checkpatch: allow multi-statement declarative macros.

Declarative macros, which declare/define storage (at either file or function scope), cannot be wrapped in do-while statements. So checkpatch advice is incorrect here.

The code has an $exceptions regex which allows multiple statements based on the macro name, etc; /DECLARE_PER_CPU|DEFINE_PER_CPU/ are currently accepted, widen those to accept /DECLARE|DEFINE/.

cc Andy Whitcroft <[email protected]> # (maintainer:CHECKPATCH)
cc Joe Perches <[email protected]> # (maintainer:CHECKPATCH)
cc Dwaipayan Ray <[email protected]> # (reviewer:CHECKPATCH)
cc Lukas Bulwahn <[email protected]> # (reviewer:CHECKPATCH)
---
 scripts/checkpatch.pl | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +3 -2
index 9c4c4a61bc83..cddf4c416523 100755
@@ -5901,6 +5901,7 @@ sub process {
 			}
 		}
 
+# except for declarative macros (whether file or function scope),
 # multi-statement macros should be enclosed in a do while loop, grab the
 # first statement and ensure its the whole macro if its not enclosed
 # in a known good container
@@ -5958,8 +5959,8 @@ sub process {
 				$Declare|
 				module_param_named|
 				MODULE_PARM_DESC|
-				DECLARE_PER_CPU|
-				DEFINE_PER_CPU|
+				DECLARE|
+				DEFINE|
 				__typeof__\(|
 				union|
 				struct|
Signature · 1 line
2.45.0
maintainer
#1 lore raw
Quoted 7 lines · Jim Cromie

Declarative macros, which declare/define storage (at either file or function scope), cannot be wrapped in do-while statements. So checkpatch advice is incorrect here.

The code has an $exceptions regex which allows multiple statements based on the macro name, etc; /DECLARE_PER_CPU|DEFINE_PER_CPU/ are currently accepted, widen those to accept /DECLARE|DEFINE/.

It seems this exempts too large a number of these macros

$ git grep -P '^\s*\#\s*define\s+\w*(?:DECLARE|DEFINE)\w*'|wc -l
5075

How about somehow limiting these exemptions more strictly?

scripts/checkpatch.pl

Quoted 1 line
scripts/checkpatch.pl +0 -0

[]

Quoted 19 lines
scripts/checkpatch.pl +3 -2
@@ -5901,6 +5901,7 @@ sub process {
 			}
 		}
 
+# except for declarative macros (whether file or function scope),
 # multi-statement macros should be enclosed in a do while loop, grab the
 # first statement and ensure its the whole macro if its not enclosed
 # in a known good container
@@ -5958,8 +5959,8 @@ sub process {
 				$Declare|
 				module_param_named|
 				MODULE_PARM_DESC|
-				DECLARE_PER_CPU|
-				DEFINE_PER_CPU|
+				DECLARE|
+				DEFINE|
 				__typeof__\(|
 				union|
 				struct|
#2 lore raw
Quoted 6 lines · Joe Perches
Quoted 4 lines · Jim Cromie

Declarative macros, which declare/define storage (at either file or function scope), cannot be wrapped in do-while statements. So checkpatch advice is incorrect here.

Quoted 9 lines
Quoted 3 lines

The code has an $exceptions regex which allows multiple statements based on the macro name, etc; /DECLARE_PER_CPU|DEFINE_PER_CPU/ are currently accepted, widen those to accept /DECLARE|DEFINE/.

It seems this exempts too large a number of these macros

$ git grep -P '^\s*\#\s*define\s+\w*(?:DECLARE|DEFINE)\w*'|wc -l
5075

wow, thats more than Id have thought.

Quoted 1 line

How about somehow limiting these exemptions more strictly?

agreed. I'll just add my 1 exceptional macro name. resending shortly.

maintainer
#3 lore raw
Quoted 17 lines · On Thu, 2024-05-16 at 09:20 -0600, [email protected] wrote:
Quoted 6 lines · Joe Perches
Quoted 4 lines · Jim Cromie

Declarative macros, which declare/define storage (at either file or function scope), cannot be wrapped in do-while statements. So checkpatch advice is incorrect here.

Quoted 9 lines
Quoted 3 lines

The code has an $exceptions regex which allows multiple statements based on the macro name, etc; /DECLARE_PER_CPU|DEFINE_PER_CPU/ are currently accepted, widen those to accept /DECLARE|DEFINE/.

It seems this exempts too large a number of these macros

$ git grep -P '^\s*\#\s*define\s+\w*(?:DECLARE|DEFINE)\w*'|wc -l
5075
Quoted 6 lines

wow, thats more than Id have thought.

Quoted 1 line

How about somehow limiting these exemptions more strictly?

agreed. I'll just add my 1 exceptional macro name. resending shortly.

Is this macro used in a lot of places? Otherwise, why not just ignore the macro where it occurs?