diff mbox series

[1/1] checkpatch: check for malformed comment block.

Message ID 20181213175552.14857-2-wainersm@redhat.com (mailing list archive)
State New, archived
Headers show
Series checkpatch: checker for comment block | expand

Commit Message

Wainer dos Santos Moschetta Dec. 13, 2018, 5:55 p.m. UTC
Currently scripts/checkpatch.pl does not check if multiline
comments follow the QEMU's coding sytle.

It is added a check for multiline comments that warns about:
    1. block doesn't begin on its own line.
    2. line in the block doesn't start with asterisk.
    3. block doesn't end on its own line.

Signed-off-by: Wainer dos Santos Moschetta <wainersm@redhat.com>
---
 scripts/checkpatch.pl | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
diff mbox series

Patch

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 60f6f89a27..5abb579ed7 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -1858,6 +1858,38 @@  sub process {
 		$line =~ s@//.*@@;
 		$opline =~ s@//.*@@;
 
+# check for malformed comment block.
+		if ($rawline =~ m{/\*} && $rawline !~ m{\*\/}) {
+			if ($rawline !~ m{^.\s*/\*+$}) {
+				WARN("comment block should begin on its own" .
+					" line\n" . $herecurr);
+			}
+
+			my $rel_line = 1;
+			my $reported = 0;
+			my $comment_line = '';
+			my $herecurr = '';
+			do {
+				$comment_line = $rawlines[$rel_line + $linenr
+					- 1];
+				$herecurr = "#".($linenr + $rel_line) .
+					": FILE: ".$realfile .
+					":".($realline + $rel_line)."\n" .
+					$comment_line."\n";
+				if (!$reported && $comment_line !~ m{^.\s*\*}) {
+					WARN("line in comment block should" .
+						" start with asterisk\n" .
+						$herecurr);
+					$reported = 1;
+				}
+				$rel_line++;
+			} while ($comment_line && $comment_line !~ m{\*\/});
+
+			if ($comment_line && $comment_line !~ m{^.\s*\*+\/}) {
+				WARN("comment block should end on its own" .
+					" line\n".$herecurr);
+			}
+		}
 # check for global initialisers.
 		if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) {
 			ERROR("do not initialise globals to 0 or NULL\n" .