From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Andy Whitcroft <apw@canonical.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] checkpatch: Improve MACRO_ARG_PRECEDENCE test
Date: Tue, 13 Sep 2016 23:57:49 -0700 [thread overview]
Message-ID: <60229d13399f9b6509db5a32e30d4c16951a60cd.1473836073.git.joe@perches.com> (raw)
It is possible for a multiple line macro definition to have a false positive
report when an argument is used on a line after a continuation \.
This line might have a leading '+' as the initial character that could be
confused by checkpatch as an operator.
Avoid the leading character on multiple line macro definitions.
Signed-off-by: Joe Perches <joe@perches.com>
---
scripts/checkpatch.pl | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index ea1a7ad..0ef3d83 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4833,13 +4833,31 @@ sub process {
}
}
+
+ # Make $define_stmt single line, comment-free, etc
+ my @stmt_array = split('\n', $define_stmt);
+ my $first = 1;
+ $define_stmt = "";
+ foreach my $l (@stmt_array) {
+ $l =~ s/\\$//;
+ if ($first) {
+ $define_stmt = $l;
+ $first = 0;
+ } elsif ($l =~ /^[\+ ]/) {
+ $define_stmt .= substr($l, 1);
+ }
+ }
+ $define_stmt =~ s/$;//g;
+ $define_stmt =~ s/\s+/ /g;
+ $define_stmt = trim($define_stmt);
+
# check if any macro arguments are reused (ignore '...' and 'type')
foreach my $arg (@def_args) {
next if ($arg =~ /\.\.\./);
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;
+ $tmp =~ s/\#+\s*$arg\b//g;
$tmp =~ s/\b$arg\s*\#\#//g;
my $use_cnt = $tmp =~ s/\b$arg\b//g;
if ($use_cnt > 1) {
--
2.10.0.rc2.1.g053435c
reply other threads:[~2016-09-14 6:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=60229d13399f9b6509db5a32e30d4c16951a60cd.1473836073.git.joe@perches.com \
--to=joe@perches.com \
--cc=akpm@linux-foundation.org \
--cc=apw@canonical.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.