Re: [PATCH] checkpatch: Fix false positive on empty block comment lines

From: Joe Perches
Date: Fri Oct 02 2020 - 15:39:18 EST


On Fri, 2020-10-02 at 21:15 +0200, Łukasz Stelmach wrote:
> To avoid false positives in presence of SPDX-License-Identifier in
> networking files it is required to increase the leeway for empty block
> comment lines by one line.

Thanks.

An example in the commit description would be nice.

The intent here is to avoid the below error so the
second line of a networking file can be an initial blank

/*

$ ./scripts/checkpatch.pl -f drivers/net/Space.c
WARNING: networking block comments don't use an empty /* line, use /* Comment...
#3: FILE: drivers/net/Space.c:3:
+/*
+ * INET An implementation of the TCP/IP protocol suite for the LINUX

total: 0 errors, 1 warnings, 0 checks, 155 lines checked

> Signed-off-by: Łukasz Stelmach <l.stelmach@xxxxxxxxxxx>
> ---
> scripts/checkpatch.pl | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index a213cdb82ab0..60e10da4cccb 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3460,7 +3460,7 @@ sub process {
> if ($realfile =~ m@^(drivers/net/|net/)@ &&
> $prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ &&
> $rawline =~ /^\+[ \t]*\*/ &&
> - $realline > 2) {
> + $realline > 3) {
> WARN("NETWORKING_BLOCK_COMMENT_STYLE",
> "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
> }

Maybe add a comment in the code too:

---
scripts/checkpatch.pl | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index a213cdb82ab0..632c543b108d 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3457,10 +3457,11 @@ sub process {

# Block comment styles
# Networking with an initial /*
+# allow an initial blank /* at the top of the file with or without an SPDX line
if ($realfile =~ m@^(drivers/net/|net/)@ &&
$prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ &&
$rawline =~ /^\+[ \t]*\*/ &&
- $realline > 2) {
+ $realline > 3) {
WARN("NETWORKING_BLOCK_COMMENT_STYLE",
"networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
}