[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1424461955.18211.15.camel@perches.com>
Date: Fri, 20 Feb 2015 11:52:35 -0800
From: Joe Perches <joe@...ches.com>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: b.a.t.m.a.n@...ts.open-mesh.org, linux-kernel@...r.kernel.org,
Dan Carpenter <dan.carpenter@...cle.com>,
Marek Lindner <mareklindner@...mailbox.ch>
Subject: [PATCH] checkpatch: Improve "no space is necessary after a cast"
test
The "no space is necessary after a cast" sizeof exclusion
doesn't work properly.
The test reports a false positive for code like:
BUILD_BUG_ON(sizeof(struct batadv_bla_claim_dst) != 6);
Make it work, simplify the exclusions, and add some comments.
Signed-off-by: Joe Perches <joe@...ches.com>
Reported-by: Marek Lindner <mareklindner@...mailbox.ch>
---
scripts/checkpatch.pl | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d124359..2898e49 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2552,9 +2552,16 @@ sub process {
}
}
- if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;:\?\(\{\}\[\<\>]|&&|\|\||\\$)/ &&
- (!defined($1) || $1 !~ /sizeof\s*/)) {
- if (CHK("SPACING",
+# check for space after cast like "(int) foo" or "(struct foo) bar"
+# avoid checking a few false positives:
+# "sizeof(<type>)" or "__alignof__(<type>)"
+# function pointer declarations like "(*foo)(int) = bar;"
+# structure definitions like "(struct foo) { 0 };"
+# multiline macros that define functions
+# known attributes or the __attribute__ keyword
+ if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$|$Attribute|__attribute__))/ &&
+ (!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) {
+ if (CHK("SPACING",
"No space is necessary after a cast\n" . $herecurr) &&
$fix) {
$fixed[$fixlinenr] =~
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists