Skip to contentSkip to conversation

scripts: coccinelle: add check for uncessary double unlikely() calls

PATCH In review Enrico Weigelt, metux IT consult 2 participants 2 messages Jun 5, 2019 – Jul 15, 2019 Coccinelle/Semantic Patches (SmPL)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scripts: coccinelle: add check for uncessary double unlikely() calls

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.

---
 scripts/coccinelle/api/double_unlikely.cocci | 35 ++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 scripts/coccinelle/api/double_unlikely.cocci
scripts/coccinelle/api/double_unlikely.cocci new file +35 -0
new file mode 100644
index 0000000..0b9bb3b
@@ -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 <[email protected]>
+//
+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)
Signature · 1 line
1.9.1
#1 lore raw

My software development attention was caught also by your proposal.

I would appreciate a message subject without a typo.

scripts/coccinelle/api/double_unlikely.cocci line 11

Quoted 4 lines
scripts/coccinelle/api/double_unlikely.cocci new file +4 -0
+virtual patch
+virtual context
+virtual org
+virtual report

These metavariables are not used in the subsequent code in this approach for the semantic patch language.

Fine-tuning might become relevant also for the change specifications.
https://lore.kernel.org/lkml/[email protected]/

Would you like to contribute an extended script version?

Regards,
Markus