From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752668AbdDIR7Z (ORCPT ); Sun, 9 Apr 2017 13:59:25 -0400 Received: from smtprelay0028.hostedemail.com ([216.40.44.28]:33524 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752495AbdDIR7Q (ORCPT ); Sun, 9 Apr 2017 13:59:16 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::,RULES_HIT:41:355:379:541:800:960:973:982:988:989:1260:1345:1359:1431:1437:1534:1541:1711:1730:1747:1777:1792:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3870:3874:4321:4605:5007:6119:6261:7514:7875:7903:9592:10004:10848:11026:11232:11473:11658:11914:12043:12114:12438:12555:12895:12986:13069:13161:13221:13229:13311:13357:14181:14384:14394:14721:21080:21451:30054,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: gold60_6d9f491430e47 X-Filterd-Recvd-Size: 2260 From: Joe Perches To: Andy Whitcroft Cc: Alfonso Lima , Andreas Mohr , linux-kernel@vger.kernel.org Subject: [PATCH V2] checkpatch: Improve MULTISTATEMENT_MACRO_USE_DO_WHILE test Date: Sun, 9 Apr 2017 10:59:11 -0700 Message-Id: X-Mailer: git-send-email 2.10.0.rc2.1.g053435c In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The logic currrently misses macros that start with an if statement. e.g.: #define foo(bar) if (bar) baz; Add a test for macro content that starts with if Original-patch-by: Alfonso Lima Reported-by: Andreas Mohr Signed-off-by: Joe Perches --- V2: V1 was done incorrectly against a much older version of checkpatch and so rolled back several improvements. I forgot I had used git checkout -- scripts/checkpatch.pl and then edited that. scripts/checkpatch.pl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index e8d8481b24c8..2468ed01b333 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -4849,8 +4849,10 @@ sub process { $dstat !~ /^\(\{/ && # ({... $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/) { - - if ($dstat =~ /;/) { + if ($dstat =~ /^\s*if\b/) { + ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE", + "Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic defects\n" . "$herectx"); + elsif ($dstat =~ /;/) { ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE", "Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx"); } else { -- 2.10.0.rc2.1.g053435c