All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] checkpatch: check for nested (un)?likely calls
@ 2019-08-27 16:55 Denis Efremov
  2019-08-27 17:21 ` Joe Perches
  2019-08-28 13:32 ` [PATCH v2] checkpatch: check for nested unlikely calls Denis Efremov
  0 siblings, 2 replies; 5+ messages in thread
From: Denis Efremov @ 2019-08-27 16:55 UTC (permalink / raw)
  To: Andy Whitcroft, Joe Perches; +Cc: Denis Efremov, linux-kernel

IS_ERR, IS_ERR_OR_NULL, IS_ERR_VALUE already contain unlikely optimization
internally. Thus, there is no point in calling these functions 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/

Signed-off-by: Denis Efremov <efremov@linux.com>
---
 scripts/checkpatch.pl | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 93a7edfe0f05..81dace5ceea5 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6480,6 +6480,13 @@ sub process {
 			     "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
 		}
 
+# nested likely/unlikely calls
+		if ($perl_version_ok &&
+		    $line =~ /\b(?:(?:un)?likely)\s*\(!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?)\s*${balanced_parens}\s*\)/) {
+			WARN("LIKELY_MISUSE",
+			     "nested (un)?likely calls, unlikely already used in $1 internally\n" . $herecurr);
+		}
+
 # whine mightly about in_atomic
 		if ($line =~ /\bin_atomic\s*\(/) {
 			if ($realfile =~ m@^drivers/@) {
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-08-28 15:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-27 16:55 [PATCH] checkpatch: check for nested (un)?likely calls Denis Efremov
2019-08-27 17:21 ` Joe Perches
2019-08-27 17:32   ` Denis Efremov
2019-08-28 13:32 ` [PATCH v2] checkpatch: check for nested unlikely calls Denis Efremov
2019-08-28 15:36   ` Denis Efremov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.