diff options
author | Joe Perches <joe@perches.com> | 2014-12-10 18:51:46 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2014-12-10 20:41:11 -0500 |
commit | abb08a53883ed7afbe3f0ac9444805042f473a63 (patch) | |
tree | eed4ba0882422e17763c65ceef9ce66d11bf79bc /scripts | |
parent | 36061e380618201a558e01d2c2ac6217ea331523 (diff) |
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')
-rwxr-xr-x | scripts/checkpatch.pl | 8 |
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 { | |||
4482 | } | 4482 | } |
4483 | } | 4483 | } |
4484 | 4484 | ||
4485 | # check for mask then right shift without a parentheses | ||
4486 | if ($^V && $^V ge 5.10.0 && | ||
4487 | $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ && | ||
4488 | $4 !~ /^\&/) { # $LvalOrFunc may be &foo, ignore if so | ||
4489 | WARN("MASK_THEN_SHIFT", | ||
4490 | "Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr); | ||
4491 | } | ||
4492 | |||
4485 | # check for bad placement of section $InitAttribute (e.g.: __initdata) | 4493 | # check for bad placement of section $InitAttribute (e.g.: __initdata) |
4486 | if ($line =~ /(\b$InitAttribute\b)/) { | 4494 | if ($line =~ /(\b$InitAttribute\b)/) { |
4487 | my $attr = $1; | 4495 | my $attr = $1; |