diff options
author | Joe Perches <joe@perches.com> | 2015-04-16 15:44:05 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-04-17 09:03:56 -0400 |
commit | 6ab3a9701e00c2a085bac6a7a9bdcf8fc5eca6c5 (patch) | |
tree | 155ea8740728586cc4f8eb933158861a0953f41c /scripts | |
parent | d43698e8abb58a6ac47d16e0f47bb55f452e4fc4 (diff) |
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@perches.com>
Reported-by: Marek Lindner <mareklindner@neomailbox.ch>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/checkpatch.pl | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index d12435992dea..421bbb47844f 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -2552,8 +2552,15 @@ sub process { | |||
2552 | } | 2552 | } |
2553 | } | 2553 | } |
2554 | 2554 | ||
2555 | if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;:\?\(\{\}\[\<\>]|&&|\|\||\\$)/ && | 2555 | # check for space after cast like "(int) foo" or "(struct foo) bar" |
2556 | (!defined($1) || $1 !~ /sizeof\s*/)) { | 2556 | # avoid checking a few false positives: |
2557 | # "sizeof(<type>)" or "__alignof__(<type>)" | ||
2558 | # function pointer declarations like "(*foo)(int) = bar;" | ||
2559 | # structure definitions like "(struct foo) { 0 };" | ||
2560 | # multiline macros that define functions | ||
2561 | # known attributes or the __attribute__ keyword | ||
2562 | if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$|$Attribute|__attribute__))/ && | ||
2563 | (!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) { | ||
2557 | if (CHK("SPACING", | 2564 | if (CHK("SPACING", |
2558 | "No space is necessary after a cast\n" . $herecurr) && | 2565 | "No space is necessary after a cast\n" . $herecurr) && |
2559 | $fix) { | 2566 | $fix) { |