From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754772AbcIMFnQ (ORCPT ); Tue, 13 Sep 2016 01:43:16 -0400 Received: from smtprelay0137.hostedemail.com ([216.40.44.137]:42018 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754616AbcIMFnL (ORCPT ); Tue, 13 Sep 2016 01:43:11 -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:1437:1534:1541:1711:1730:1747:1777:1792:2197:2199:2393:2553:2559:2562:3138:3139:3140:3141:3142:3352:3653:3865:3867:3868:3874:4321:4605:5007:6119:6261:7875:7903:10004:10848:11026:11473:11658:11914:12043:12438:12555:13069:13255:13311:13357:14181:14384:14394:14721:21080:21221:21451:30054:30064:30070:30090,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: stamp57_38965623f1245 X-Filterd-Recvd-Size: 2337 From: Joe Perches To: Andrew Morton , Andy Whitcroft Cc: Julia Lawall , Dan Carpenter , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] checkpatch: Add --strict test for precedence challenged macro arguments Date: Mon, 12 Sep 2016 22:43:03 -0700 Message-Id: <940815449599d405bfcf8e4c5d511a8fb3ca23bf.1473744906.git.joe@perches.com> 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 Add a test for macro arguents that have a non-comma leading or trailing operator where the argument isn't parenthesized to avoid possible precedence issues. Signed-off-by: Joe Perches --- scripts/checkpatch.pl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index f135f8e..6e067e5 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -4836,7 +4836,7 @@ sub process { # check if any macro arguments are reused (ignore '...' and 'type') foreach my $arg (@def_args) { next if ($arg =~ /\.\.\./); - next if ($arg =~ /^type$/); + next if ($arg =~ /^type$/i); my $tmp = $define_stmt; $tmp =~ s/\b(typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g; $tmp =~ s/\#\s*$arg\b//g; @@ -4846,6 +4846,13 @@ sub process { CHK("MACRO_ARG_REUSE", "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx"); } ++# check if any macro arguments may have other precedence issues + if ($define_stmt =~ m/($Operators)?\s*\b$arg\b\s*($Operators)?/m && + ((defined($1) && $1 ne ',') || + (defined($2) && $2 ne ','))) { + CHK("MACRO_ARG_PRECEDENCE", + "Macro argument '$arg' may be better as '($arg)' to avoid precedence issues\n" . "$herectx"); + } } # check for macros with flow control, but without ## concatenation -- 2.10.0.rc2.1.g053435c