From: Joe Perches Date: Fri, 13 Feb 2015 22:38:38 +0000 (-0800) Subject: checkpatch: add likely/unlikely comparison misuse test X-Git-Tag: android-x86-4.4-r3~331^2~51 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=acd9362c248e33187629c950badb834b73e20e41;p=android-x86%2Fkernel.git checkpatch: add likely/unlikely comparison misuse test Add a test for probably likely/unlikely misuses where the comparison is likely misplaced if (likely(foo) > 0) vs if (likely(foo > 0)) Signed-off-by: Joe Perches Cc: Christoph Jaeger Cc: Julia Lawall Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 786017d4d057..41223c946808 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -5239,6 +5239,13 @@ sub process { "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr); } +# likely/unlikely comparisons similar to "(likely(foo) > 0)" + if ($^V && $^V ge 5.10.0 && + $line =~ /\b((?:un)?likely)\s*\(\s*$FuncArg\s*\)\s*$Compare/) { + WARN("LIKELY_MISUSE", + "Using $1 should generally have parentheses around the comparison\n" . $herecurr); + } + # whine mightly about in_atomic if ($line =~ /\bin_atomic\s*\(/) { if ($realfile =~ m@^drivers/@) {