Skip to content

Commit acd9362

Browse files
JoePerchestorvalds
authored andcommitted
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 <joe@perches.com> Cc: Christoph Jaeger <cj@linux.com> Cc: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0d7835f commit acd9362

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

scripts/checkpatch.pl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5239,6 +5239,13 @@ sub process {
52395239
"#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
52405240
}
52415241

5242+
# likely/unlikely comparisons similar to "(likely(foo) > 0)"
5243+
if ($^V && $^V ge 5.10.0 &&
5244+
$line =~ /\b((?:un)?likely)\s*\(\s*$FuncArg\s*\)\s*$Compare/) {
5245+
WARN("LIKELY_MISUSE",
5246+
"Using $1 should generally have parentheses around the comparison\n" . $herecurr);
5247+
}
5248+
52425249
# whine mightly about in_atomic
52435250
if ($line =~ /\bin_atomic\s*\(/) {
52445251
if ($realfile =~ m@^drivers/@) {

0 commit comments

Comments
 (0)