From nobody Thu Dec 18 23:37:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1533830719035938.9147600255926; Thu, 9 Aug 2018 09:05:19 -0700 (PDT) Received: from localhost ([::1]:51749 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnnQu-0006MW-1R for importer@patchew.org; Thu, 09 Aug 2018 12:05:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fnnMH-0002b0-5o for qemu-devel@nongnu.org; Thu, 09 Aug 2018 12:00:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fnnMG-0002hf-3W for qemu-devel@nongnu.org; Thu, 09 Aug 2018 12:00:17 -0400 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:44240) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fnnMF-0002hJ-Ry for qemu-devel@nongnu.org; Thu, 09 Aug 2018 12:00:16 -0400 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1fnnMD-0003SE-Ql; Thu, 09 Aug 2018 17:00:13 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Thu, 9 Aug 2018 17:00:11 +0100 Message-Id: <20180809160011.17225-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.17.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PATCH] scripts/checkpatch.pl: Enforce multiline comment syntax X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Thomas Huth , patches@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" We now require Linux-kernel-style multiline comments: /* * line one * line two */ Enforce this in checkpatch.pl, by backporting the relevant parts of the Linux kernel's checkpatch.pl. (The only changes needed are that Linux's checkpatch.pl WARN() function takes an extra argument that ours does not.) The kernel's checkpatch does not enforce "leading /* on a line of its own, so that part is unique to QEMU's checkpatch. Sample warning output: WARNING: Block comments use a leading /* on a separate line #34: FILE: hw/intc/arm_gicv3_common.c:39: + /* Older versions of QEMU had a bug in the handling of state save/rest= ore Signed-off-by: Peter Maydell Acked-by: Thomas Huth Reviewed-by: Markus Armbruster --- I'm still not used to the leeading-/*-on-it's-own style, so having checkpatch catch my lapses is handy... I used WARN level severity mostly because Linux does. --- scripts/checkpatch.pl | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 42e1c50dd80..18bc3c59c85 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1566,6 +1566,54 @@ sub process { # check we are in a valid C source file if not then ignore this hunk next if ($realfile !~ /\.(h|c|cpp)$/); =20 +# Block comment styles + + # Block comments use /* on a line of its own + if ($rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/ + $rawline =3D~ 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 =3D~ /$;[ \t]*$/ && #ends in comment + $prevrawline =3D~ /^\+.*?\/\*/ && #starting /* + $prevrawline !~ /\*\/[ \t]*$/ && #no trailing */ + $rawline =3D~ /^\+/ && #line is new + $rawline !~ /^\+[ \t]*\*/) { #no leading * + WARN("Block comments use * on subsequent lines\n" . $hereprev); + } + +# Block comments use */ on trailing lines + if ($rawline !~ m@^\+[ \t]*\*/[ \t]*$@ && #trailing */ + $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/ + $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ && #trailing **/ + $rawline =3D~ m@^\+[ \t]*.+\*\/[ \t]*$@) { #non blank */ + WARN("Block comments use a trailing */ on a separate line\n" . $herecur= r); + } + +# Block comment * alignment + if ($prevline =3D~ /$;[ \t]*$/ && #ends in comment + $line =3D~ /^\+[ \t]*$;/ && #leading comment + $rawline =3D~ /^\+[ \t]*\*/ && #leading * + (($prevrawline =3D~ /^\+.*?\/\*/ && #leading /* + $prevrawline !~ /\*\/[ \t]*$/) || #no trailing */ + $prevrawline =3D~ /^\+[ \t]*\*/)) { #leading * + my $oldindent; + $prevrawline =3D~ m@^\+([ \t]*/?)\*@; + if (defined($1)) { + $oldindent =3D expand_tabs($1); + } else { + $prevrawline =3D~ m@^\+(.*/?)\*@; + $oldindent =3D expand_tabs($1); + } + $rawline =3D~ m@^\+([ \t]*)\*@; + my $newindent =3D $1; + $newindent =3D expand_tabs($newindent); + if (length($oldindent) ne length($newindent)) { + WARN("Block comments should align the * on each line\n" . $hereprev); + } + } + # Check for potential 'bare' types my ($stat, $cond, $line_nr_next, $remain_next, $off_next, $realline_next); --=20 2.17.1