qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] checkpatch: better pattern for inline comments
@ 2022-11-07 14:56 Michael S. Tsirkin
  0 siblings, 0 replies; only message in thread
From: Michael S. Tsirkin @ 2022-11-07 14:56 UTC (permalink / raw)
  To: qemu-devel
  Cc: Philippe Mathieu-Daudé, Marc-André Lureau,
	Paolo Bonzini, Richard Henderson, Laurent Vivier

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 | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index e3e3b43076..be37c9e0bf 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -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
-- 
MST



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-07 14:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-07 14:56 [PATCH] checkpatch: better pattern for inline comments Michael S. Tsirkin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).