Skip to contentSkip to conversation

checkpatch: better pattern for inline comments

PATCH Superseded Michael S. Tsirkin 1 participant 1 message Nov 7, 2022 Checkpatch

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 checkpatch: better pattern for inline comments

checkpatch is unhappy about this line:

WARNING: Block comments use a leading /* on a separate line #50: FILE: hw/acpi/nvdimm.c:1074:
+ aml_equal(aml_sizeof(pckg), aml_int(1)) /* 1 element? */));

but there's nothing wrong with it - the check is just too simplistic. It will also miss lines which mix inline and block comments.

Instead, let's strip all inline comments from a line and then check for block comments.

---
 scripts/checkpatch.pl | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
scripts/checkpatch.pl +9 -4
index e3e3b43076..be37c9e0bf 100755
@@ -1681,10 +1681,15 @@ sub process {
 # Block comment styles
 
 		# Block comments use /* on a line of its own
-		if ($rawline !~ m@^\+.*/\*.*\*/[ \t)}]*$@ &&	#inline /*...*/
-		    $rawline =~ m@^\+.*/\*\*?+[ \t]*[^ \t]@) { # /* or /** non-blank
-			WARN("Block comments use a leading /* on a separate line\n" . $herecurr);
-		}
+		{
+                    # remove inline #inline /*...*/
+                    my $commentline = $rawline;
+                    while ($commentline =~ s@^(\+.*)/\*.*\*/@$1@o) {
+                    }
+                    if ($commentline =~ m@^\+.*/\*\*?+[ \t]*[^ \t]@) { # /* or /** non-blank
+                            WARN("Block comments use a leading /* on a separate line\n" . $herecurr);
+                    }
+                }
 
 # Block comments use * on subsequent lines
 		if ($prevline =~ /$;[ \t]*$/ &&			#ends in comment
Signature · 1 line
MST