History

checkpatch: check for nested (un)?likely() calls

IS_ERR(), IS_ERR_OR_NULL(), IS_ERR_VALUE() and WARN*() already contain unlikely() optimization internally. Thus, there is no point in calling these functions and defines under likely()/unlikely(). This check is based on the coccinelle rule developed by Enrico Weigelt https://lore.kernel.org/lkml/1559767582-11081-1-git-send-email-info@metux.net/

Denis Efremov committed 7 years ago

Commit de3f1861 parent c7cc8d71 file · +6 −0Browse files

Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all

Unified · Split

scripts/checkpatch.pl+6−0
@@ -6507,6 +6507,12 @@ sub process { · 6506 unmodified lines
6507 "Using $1 should generally have parentheses around the comparison\n" . $herecurr);6507 "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
6508 }6508 }
6509 6509
6510# nested likely/unlikely calls
6511 if ($line =~ /\b(?:(?:un)?likely)\s*\(\s*!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?|WARN)/) {
6512 WARN("LIKELY_MISUSE",
6513 "nested (un)?likely() calls, $1 already uses unlikely() internally\n" . $herecurr);
6514 }
6515
6510# whine mightly about in_atomic6516# whine mightly about in_atomic
6511 if ($line =~ /\bin_atomic\s*\(/) {6517 if ($line =~ /\bin_atomic\s*\(/) {
6512 if ($realfile =~ m@^drivers/@) {6518 if ($realfile =~ m@^drivers/@) {