Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit abb08a53 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds
Browse files

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: default avatarJoe Perches <joe@perches.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 36061e38
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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;