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

Lukas Bulwahn lukas.bulwahn at gmail.com
Thu Oct 1 08:22:03 UTC 2020



On Thu, 1 Oct 2020, Dwaipayan Ray wrote:

> Checkpatch.pl doesn't have a check for excluding while (...) {...}
> blocks from MULTISTATEMENT_MACRO_USE_DO_WHILE error.
> 
> For example, running checkpatch.pl on the file mm/access.c in the
> kernel generates the following error:
> 
> ERROR: Macros with complex values should be enclosed in parentheses
> +#define copy_from_kernel_nofault_loop(dst, src, len, type, err_label)	\
> +	while (len >= sizeof(type)) {					\
> +		__get_kernel_nofault(dst, src, type, err_label);	\
> +		dst += sizeof(type);					\
> +		src += sizeof(type);					\
> +		len -= sizeof(type);					\
> +	}
> 
> The error is misleading for this case. Enclosing it in a paranthesis
> doesn't make any sense.
>

s/a paranthesis/parentheses/

> Checkpatch already has an exception list for such common macro types.
> Added a new exception for while (...) {...} style blocks to the same.
> This effectively fixed the wrong error message.
>

This seems easier to understand and to judge than the other patch.

We will still need an evaluation, though. Theodoros, maybe you can help us 
here.

Dwaipayan, looks good to me. Do you fix up the spelling mistake and then 
send that patch to Joe and lkml?
 
> 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 72c4072307ea..c2c211374662 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -5342,6 +5342,7 @@ sub process {
>  			    $dstat !~ /^\.$Ident\s*=/ &&				# .foo =
>  			    $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ &&		# stringification #foo
>  			    $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ &&	# do {...} while (...); // do {...} while (...)
> +			    $dstat !~ /^while\s*$Constant\s*$Constant\s*$/ &&			# while (...) {...}

Is it just the tab setting in my email client or is there a tab too much 
that it does not align with the other comments?

>  			    $dstat !~ /^for\s*$Constant$/ &&				# for (...)
>  			    $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ &&	# for (...) bar()
>  			    $dstat !~ /^do\s*{/ &&					# do {...
> -- 
> 2.27.0
> 
> 


More information about the Linux-kernel-mentees mailing list