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
65076507 "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
65086508 }
65096509
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+
65106516 # whine mightly about in_atomic
65116517 if ($line =~ /\bin_atomic\s*\(/) {
65126518 if ($realfile =~ m@^drivers/@) {