From patchwork Tue Jan 16 14:17:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 861656 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ftHsz3K6"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zLYGP0PPpz9s7v for ; Wed, 17 Jan 2018 01:57:01 +1100 (AEDT) Received: from localhost ([::1]:39454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebSfb-0000sr-3q for incoming@patchwork.ozlabs.org; Tue, 16 Jan 2018 09:56:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50937) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebS4d-0003bl-QK for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebS4Y-0005Pd-5o for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:47 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:46887) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ebS4X-0005P7-W1 for qemu-devel@nongnu.org; Tue, 16 Jan 2018 09:18:42 -0500 Received: by mail-wr0-x241.google.com with SMTP id g21so15303908wrb.13 for ; Tue, 16 Jan 2018 06:18:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=3cg63NDUmgBpGpBxxApA/29oZGAjDVw5iBbPXqLg6Tc=; b=ftHsz3K6y0+rFJ+G1Ty59drig3o80yC58YtyAxQN6YfaavuAppvddlYYYRUhWjcqrH klUhJCG7kIumbshnZ6ka7+NaQJXrNVEhaDgMcdDAh9PswglvSg7ChaGj2gNywBISmZR6 JijJAOEHjt6A0yjmODQUSsvQkGkyjSbm5teWbDtQEaBcraWolun6CnKbvdYHCJU7wir2 QmClQHVRiAiq64xpogtm2Bv7UgN5vgswQzODGRXpIgW5slE2ECsQoCmcqDrmk3kl1p2q P2p8FGCpt33EB3jlkYIJ56SHtdEP9Od27NfpiZDifNF2B7vL8IAWScramFnE1qKerhKd qz7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=3cg63NDUmgBpGpBxxApA/29oZGAjDVw5iBbPXqLg6Tc=; b=lDDtGEeMvy8BatEjThDxww08ex0u6lRGjh7mTzrHqBAtHtcA5xCQphb+d8szkfO16N 1nfEkGZmqIxqweBoTZkaRSymSr80MN3x71I72guP8D3L0QIxaBlLMceNjjtWOrCA4ZP3 8vxJtc3ANiX+6Jq6EMdhr9EICS9SxGkZYMKUFWB+eOkTU7zIK6+uaXrzS47aHF+rqR5/ gCz9n9TxF/vwn//d0C+HUa23pHXx5TgVMSYYF/dqCdm15a0yrhXwmr/TOjXyA8kasY2X dW6IV3yXiVA/+yCIYuelAySbT9EwLZ8LQJeeiJ643dwOl3gDAM6OZMGPxc5mNSjtO+OD cq1Q== X-Gm-Message-State: AKGB3mLD9t68rLzcKJOqpjnveWPzxND4Zzsz+mKnVI+21Si6Ouv3RKZc HTbIgJtRlwqRnPCcir1CYcelr7BW X-Google-Smtp-Source: ACJfBouye/6Hc0IimSTK25ULqk8H0sN693DBjfN/f7uT9tYQ4iI8t9xP3aO8j02jfH/C5hBOloGqeQ== X-Received: by 10.223.183.23 with SMTP id l23mr26787783wre.33.1516112320702; Tue, 16 Jan 2018 06:18:40 -0800 (PST) Received: from 640k.lan (dynamic-adsl-78-12-229-84.clienti.tiscali.it. [78.12.229.84]) by smtp.gmail.com with ESMTPSA id u10sm1537758wrg.6.2018.01.16.06.18.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Jan 2018 06:18:39 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 15:17:26 +0100 Message-Id: <1516112253-14480-45-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1516112253-14480-1-git-send-email-pbonzini@redhat.com> References: <1516112253-14480-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PULL 44/51] checkpatch: Enforce proper do/while (0) style 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Eric Blake Use of a loop construct for code that is not intended to repeat does not make much idiomatic sense, except in one place: it is a common usage in macros in order to wrap arbitrary code with single-statement semantics. But when used in a macro, it is more typical for the caller to supply the trailing ';' when calling the macro. Although qemu coding style frowns on bare: if (cond) statement1; else statement2; where extra semicolons actually cause syntax errors, we still want our macro styles to be easily copied to other projects. Thus, declare it an error if we encounter any form of 'while (0)' with a semicolon in the same line. Signed-off-by: Eric Blake Message-Id: <20171201232433.25193-8-eblake@redhat.com> Signed-off-by: Paolo Bonzini --- scripts/checkpatch.pl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 3dc27d9..accba24 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -1622,6 +1622,11 @@ sub process { } } +# 'do ... while (0/false)' only makes sense in macros, without trailing ';' + if ($line =~ /while\s*\((0|false)\);/) { + ERROR("suspicious ; after while (0)\n" . $herecurr); + } + # Check relative indent for conditionals and blocks. if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) { my ($s, $c) = ($stat, $cond);