summaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2014-12-11 00:51:46 +0100
committerLinus Torvalds <torvalds@linux-foundation.org>2014-12-11 02:41:11 +0100
commitabb08a53883ed7afbe3f0ac9444805042f473a63 (patch)
treeeed4ba0882422e17763c65ceef9ce66d11bf79bc /scripts/checkpatch.pl
parentcheckpatch: fix use via symlink, make missing spelling file non-fatal (diff)
downloadlinux-abb08a53883ed7afbe3f0ac9444805042f473a63.tar.xz
linux-abb08a53883ed7afbe3f0ac9444805042f473a63.zip
checkpatch: try to avoid mask and shift errors
Shift has a higher precedence that mask so warn when a mask then shift operation is done without parentheses around the mask. This test works well for a right shift, but the left shift is pretty commonly done correctly so only warn on the right shift. Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl8
1 files changed, 8 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 853dc7f9f751..24d6702a95c2 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4482,6 +4482,14 @@ sub process {
}
}
+# check for mask then right shift without a parentheses
+ if ($^V && $^V ge 5.10.0 &&
+ $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ &&
+ $4 !~ /^\&/) { # $LvalOrFunc may be &foo, ignore if so
+ WARN("MASK_THEN_SHIFT",
+ "Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr);
+ }
+
# check for bad placement of section $InitAttribute (e.g.: __initdata)
if ($line =~ /(\b$InitAttribute\b)/) {
my $attr = $1;