LKML Archive on lore.kernel.org
 help / color / Atom feed
From: "Enrico Weigelt, metux IT consult" <info@metux.net>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] scripts: coccinelle: add check for uncessary double unlikely() calls
Date: Wed,  5 Jun 2019 22:46:22 +0200
Message-ID: <1559767582-11081-1-git-send-email-info@metux.net> (raw)

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


             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-05 20:46 Enrico Weigelt, metux IT consult [this message]
2019-07-15 19:50 ` Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1559767582-11081-1-git-send-email-info@metux.net \
    --to=info@metux.net \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lore.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lore.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lore.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lore.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lore.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lore.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lore.kernel.org/lkml/7 lkml/git/7.git
	git clone --mirror https://lore.kernel.org/lkml/8 lkml/git/8.git
	git clone --mirror https://lore.kernel.org/lkml/9 lkml/git/9.git
	git clone --mirror https://lore.kernel.org/lkml/10 lkml/git/10.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lore.kernel.org/lkml \
		linux-kernel@vger.kernel.org
	public-inbox-index lkml

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git