[Linux-kernel-mentees] [PATCH RFC 1/2] checkpatch: fix multi-statement macro checks

Lukas Bulwahn lukas.bulwahn at gmail.com
Thu Oct 1 08:14:29 UTC 2020



On Thu, 1 Oct 2020, Dwaipayan Ray wrote:

> Checkpatch.pl generates errors which are false positive for
> certain multi-statemenent macros.
> 
> The specific case investigated was whitespace separated statement
> terminated by a semicolon. Checkpatch wrongly classifies such
> as a multi-statement macro.
> 
> For example, commit 4649079b9de1 ("tracing: Make ftrace packed
> events have align of 1") when analyzed with checkpatch generates:
> 
> ERROR: Macros with multiple statements should be enclosed in a do -
> while loop
> +#define __field_packed(type, container, item)    type item;
> 
> The error is misleading in this case and should not be produced.
> The solution undertaken is to exclude any macro which doesn't
> have any non-WSP character after the first and only semicolon(;)

We all know what a semicolon is; so, you do not need to put that in 
braces.

> present in it. This shall allow macros of the form "type item;",
> "type item[size];", etc. to not generate the multi-statement macro
> error.
>

I think the core reason this might work is that it is a string without any 
semicolon and then semicolon is at the very end of this expression.

Okay, we need an evaluation if this makes the whole situation better or 
worse...

Theodoros, can you help us and run checkpatch.pl for this one rule on the 
current kernel source code before and after the patch is applied, and let 
us know which differences you observe?

Dwaipayan, can you try to do a similar evaluation on git commits?

> Signed-off-by: Dwaipayan Ray <dwaipayanray1 at gmail.com>
> ---
>  scripts/checkpatch.pl | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 9e65d21456f1..72c4072307ea 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -5346,6 +5346,7 @@ sub process {
>  			    $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ &&	# for (...) bar()
>  			    $dstat !~ /^do\s*{/ &&					# do {...
>  			    $dstat !~ /^\(\{/ &&						# ({...
> +			    $dstat !~ /^[^;]*;\s*$/ &&				# space separated statement;

I do not understand this comment "space separated statement". The example 
above was a macro for a type definition. Isn't that what you have in mind?


Give it another iteration, but I think the patch is pretty clear and so 
let us send it out to Joe and lkml with the next patch version.

Lukas

>  			    $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/)
>  			{
>  				if ($dstat =~ /^\s*if\b/) {
> -- 
> 2.27.0
> 
> 


More information about the Linux-kernel-mentees mailing list