From: Joe Perches Date: Thu, 16 Apr 2015 19:44:05 +0000 (-0700) Subject: checkpatch: improve "no space is necessary after a cast" test X-Git-Tag: firefly_0821_release~176^2~1948^2~118 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=6ab3a9701e00c2a085bac6a7a9bdcf8fc5eca6c5;p=firefly-linux-kernel-4.4.55.git 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 Reported-by: Marek Lindner Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- 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 { } } - if ($line =~ /^\+.*(\w+\s*)?\(\s*$Type\s*\)[ \t]+(?!$Assignment|$Arithmetic|[,;:\?\(\{\}\[\<\>]|&&|\|\||\\$)/ && - (!defined($1) || $1 !~ /sizeof\s*/)) { +# check for space after cast like "(int) foo" or "(struct foo) bar" +# avoid checking a few false positives: +# "sizeof()" or "__alignof__()" +# 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) {