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/
Showing the changes to scripts/checkpatch.pl (1 of 1 file). Show all
Unified · Split
| @@ -6507,6 +6507,12 @@ sub process { · 6506 unmodified lines | ||
| 6507 | 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 | 6516 | # whine mightly about in_atomic |
| 6511 | 6517 | if ($line =~ /\bin_atomic\s*\(/) { |
| 6512 | 6518 | if ($realfile =~ m@^drivers/@) { |