linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scripts: coccinelle: add check for uncessary double unlikely() calls
@ 2019-06-05 20:46 Enrico Weigelt, metux IT consult
  2019-07-15 19:50 ` Markus Elfring
  0 siblings, 1 reply; 2+ messages in thread
From: Enrico Weigelt, metux IT consult @ 2019-06-05 20:46 UTC (permalink / raw)
  To: linux-kernel

IS_ERR() and IS_ERR_OR_NULL()) already call unlikely(), therefore
expressions like "(unlikely(IS_ERR(foo))" or "(!likely(IS_ERR(foo))"
aren't needed.

This patch adds a coccinelle script that checks for that.

Signed-off-by: Enrico Weigelt <info@metux.net>
---
 scripts/coccinelle/api/double_unlikely.cocci | 35 ++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 scripts/coccinelle/api/double_unlikely.cocci

diff --git a/scripts/coccinelle/api/double_unlikely.cocci b/scripts/coccinelle/api/double_unlikely.cocci
new file mode 100644
index 0000000..0b9bb3b
--- /dev/null
+++ b/scripts/coccinelle/api/double_unlikely.cocci
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// find unncessary cases of unlikely(IS_ERR(foo))
+// IS_ERR() already calls unlikely() call
+//
+// Copyright (C) 2019 Enrico Weigelt, metux IT consult <info@metux.net>
+//
+virtual patch
+virtual context
+virtual org
+virtual report
+
+@@
+expression E;
+@@
+- unlikely(IS_ERR(E))
++ IS_ERR(E)
+
+@@
+expression E;
+@@
+- unlikely(IS_ERR_OR_NULL(E))
++ IS_ERR_OR_NULL(E)
+
+@@
+expression E;
+@@
+- likely(!IS_ERR(E))
++ !IS_ERR(E)
+
+@@
+expression E;
+@@
+- likely(!IS_ERR_OR_NULL(E))
++ !IS_ERR_OR_NULL(E)
-- 
1.9.1


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

end of thread, other threads:[~2019-07-15 19:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-05 20:46 [PATCH] scripts: coccinelle: add check for uncessary double unlikely() calls Enrico Weigelt, metux IT consult
2019-07-15 19:50 ` 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).