From patchwork Wed Feb 28 03:31:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Su Hang X-Patchwork-Id: 10246643 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B85D960211 for ; Wed, 28 Feb 2018 03:33:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA73928BAC for ; Wed, 28 Feb 2018 03:33:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F2F428BB5; Wed, 28 Feb 2018 03:33:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C585E28BAC for ; Wed, 28 Feb 2018 03:33:14 +0000 (UTC) Received: from localhost ([::1]:42018 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqsUR-0006Uz-Jl for patchwork-qemu-devel@patchwork.kernel.org; Tue, 27 Feb 2018 22:33:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49352) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqsTf-0006Ae-FK for qemu-devel@nongnu.org; Tue, 27 Feb 2018 22:32:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eqsTb-0003Uj-Fu for qemu-devel@nongnu.org; Tue, 27 Feb 2018 22:32:23 -0500 Received: from smtp20.cstnet.cn ([159.226.251.20]:58768 helo=cstnet.cn) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eqsTa-0003TZ-Qz for qemu-devel@nongnu.org; Tue, 27 Feb 2018 22:32:19 -0500 Received: from localhost.localdomain (unknown [36.110.80.218]) by APP-10 (Coremail) with SMTP id tACowAAHD3O5IpZaLn+_BQ--.6253S3; Wed, 28 Feb 2018 11:32:10 +0800 (CST) From: Su Hang To: thuth@redhat.com, eblake@redhat.com, stefanha@redhat.com Date: Wed, 28 Feb 2018 11:31:29 +0800 Message-Id: <1519788689-11967-1-git-send-email-suhang16@mails.ucas.ac.cn> X-Mailer: git-send-email 2.7.4 X-CM-TRANSID: tACowAAHD3O5IpZaLn+_BQ--.6253S3 X-Coremail-Antispam: 1UD129KBjvJXoW7CF43Cw1xAFWrCrW8Zr45GFg_yoW8Gr1rpF yUKw4YvryrKF1Ygay7tw18ArZ8Kw4rtFWxtryUZa4YyFyYgr4xKFWSkr1YkrykAwnxua47 ZFs0qryakrWj9FDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUkGb7Iv0xC_Zr1lb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I2 0VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rw A2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_JFI_Gr1l84ACjcxK6xII jxv20xvEc7CjxVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwV C2z280aVCY1x0267AKxVW8Jr0_Cr1UM2vYz4IE04k24VAvwVAKI4IrM2AIxVAIcxkEcVAq 07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20xvE14v26r1Y6r 17McIj6I8E87Iv67AKxVWxJVW8Jr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAK I48JMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI 0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y 0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxV WUJVW8JwCI42IY6xAIw20EY4v20xvaj40_WFyUJVCq3wCI42IY6I8E87Iv67AKxVWUJVW8 JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x07jn189UUU UU= X-CM-SenderInfo: pvxkt0rjrwqzpdlo2hpxfd2hldfou0/ X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 159.226.251.20 Subject: [Qemu-devel] [PATCH v3] scripts/checkpatch.pl: add check for `while` and `for` 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: qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Adding check for `while` and `for` statements, which condition has more than one line. The former checkpatch.pl can check `if` statement, which condition has more than one line, whether block misses brace round, like this: ''' if (cond1 || cond2) statement; ''' But it doesn't do the same check for `for` and `while` statements. Using `(?:...)` instead of `(...)` in regex pattern catch. Because `(?:...)` is faster and avoids unwanted side-effect. Suggested-by: Stefan Hajnoczi Suggested-by: Eric Blake Suggested-by: Thomas Huth Signed-off-by: Su Hang Reviewed-by: Darren Kenny --- scripts/checkpatch.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 10c138344fa9..bed1dbbd54d1 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -2352,9 +2352,9 @@ sub process { } } -# check for missing bracing round if etc - if ($line =~ /(^.*)\b(for|while|if)\b/ && - $line !~ /\#\s*(for|while|if)/) { +# check for missing bracing around if etc + if ($line =~ /(^.*)\b(?:for|while|if)\b/ && + $line !~ /\#\s*(?:for|while|if)/) { my ($level, $endln, @chunks) = ctx_statement_full($linenr, $realcnt, 1); if ($dbg_adv_apw) {