mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] checkpatch: Try to avoid mask and shift errors
@ 2014-10-27  5:33 Joe Perches
  0 siblings, 0 replies; only message in thread
From: Joe Perches @ 2014-10-27  5:33 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Andy Whitcroft, LKML

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>
---
 scripts/checkpatch.pl | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index d94f5d8..9b474d5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -4478,6 +4478,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;



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-10-27  5:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-27  5:33 [PATCH] checkpatch: Try to avoid mask and shift errors Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome