linux-arm-msm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 01/11] checkpatch: check for nested (un)?likely() calls
@ 2019-08-29 16:50 Denis Efremov
  2019-08-29 16:50 ` [PATCH v3 02/11] drm/msm: remove unlikely() from WARN_ON() conditions Denis Efremov
  2019-08-31  9:15 ` [PATCH v3 01/11] checkpatch: check for nested (un)?likely() calls Markus Elfring
  0 siblings, 2 replies; 8+ messages in thread
From: Denis Efremov @ 2019-08-29 16:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: Denis Efremov, Alexander Viro, Anton Altaparmakov,
	Boris Ostrovsky, Boris Pismenny, Darrick J. Wong,
	David S. Miller, Dennis Dalessandro, Dmitry Torokhov,
	Inaky Perez-Gonzalez, Juergen Gross, Leon Romanovsky,
	Mike Marciniszyn, Pali Rohár, Rob Clark, Saeed Mahameed,
	Sean Paul, linux-arm-msm, linux-fsdevel, linux-input,
	linux-ntfs-dev, linux-rdma, linux-wimax, linux-xfs, xen-devel,
	netdev, dri-devel, Joe Perches, Andrew Morton, Andy Whitcroft

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/

Signed-off-by: Denis Efremov <efremov@linux.com>
Cc: Joe Perches <joe@perches.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Whitcroft <apw@canonical.com>
---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 93a7edfe0f05..56969ce06df4 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6480,6 +6480,12 @@ sub process {
 			     "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
 		}
 
+# nested likely/unlikely calls
+		if ($line =~ /\b(?:(?:un)?likely)\s*\(\s*!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?|WARN)/) {
+			WARN("LIKELY_MISUSE",
+			     "nested (un)?likely() calls, $1 already uses unlikely() 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] 8+ messages in thread

end of thread, other threads:[~2019-09-04  4:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-29 16:50 [PATCH v3 01/11] checkpatch: check for nested (un)?likely() calls Denis Efremov
2019-08-29 16:50 ` [PATCH v3 02/11] drm/msm: remove unlikely() from WARN_ON() conditions Denis Efremov
2019-09-04  4:13   ` Bjorn Andersson
2019-08-31  9:15 ` [PATCH v3 01/11] checkpatch: check for nested (un)?likely() calls Markus Elfring
2019-08-31 15:54   ` Denis Efremov
2019-08-31 16:45     ` Markus Elfring
2019-08-31 17:07       ` Denis Efremov
2019-08-31 17:26         ` Markus Elfring

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).