2024-05-16 14:14:36

by Jim Cromie

[permalink] [raw]
Subject: [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)
Signed-off-by: Jim Cromie <[email protected]>
---
scripts/checkpatch.pl | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 9c4c4a61bc83..cddf4c416523 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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.45.0



2024-05-16 15:03:08

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 1/1] checkpatch: allow multi-statement declarative macros.

On Thu, 2024-05-16 at 08:14 -0600, Jim Cromie wrote:
> 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?

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -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|


2024-05-16 15:35:28

by Jim Cromie

[permalink] [raw]
Subject: Re: [PATCH 1/1] checkpatch: allow multi-statement declarative macros.

On Thu, May 16, 2024 at 8:43 AM Joe Perches <[email protected]> wrote:
>
> On Thu, 2024-05-16 at 08:14 -0600, Jim Cromie wrote:
> > 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
>

wow, thats more than Id have thought.

> How about somehow limiting these exemptions more strictly?

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

2024-05-17 00:38:12

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH 1/1] checkpatch: allow multi-statement declarative macros.

On Thu, 2024-05-16 at 09:20 -0600, [email protected] wrote:
> On Thu, May 16, 2024 at 8:43 AM Joe Perches <[email protected]> wrote:
> >
> > On Thu, 2024-05-16 at 08:14 -0600, Jim Cromie wrote:
> > > 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
> >
>
> wow, thats more than Id have thought.
>
> > 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?