OSDN Git Service

checkpatch: better pattern for inline comments
authorMichael S. Tsirkin <mst@redhat.com>
Mon, 7 Nov 2022 14:52:16 +0000 (09:52 -0500)
committerMichael S. Tsirkin <mst@redhat.com>
Mon, 7 Nov 2022 19:25:51 +0000 (14:25 -0500)
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.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
scripts/checkpatch.pl

index e3e3b43..bc7d478 100755 (executable)
@@ -1681,8 +1681,10 @@ 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
+               my $commentline = $rawline;
+               while ($commentline =~ s@^(\+.*)/\*.*\*/@$1@o) { # remove inline #inline /*...*/
+               }
+               if ($commentline =~ m@^\+.*/\*\*?+[ \t]*[^ \t]@) { # /* or /** non-blank
                        WARN("Block comments use a leading /* on a separate line\n" . $herecurr);
                }