[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220510154750.212913-3-yury.norov@gmail.com>
Date: Tue, 10 May 2022 08:47:30 -0700
From: Yury Norov <yury.norov@...il.com>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
David Laight <David.Laight@...LAB.COM>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Joe Perches <joe@...ches.com>,
Julia Lawall <Julia.Lawall@...ia.fr>,
Michał Mirosław <mirq-linux@...e.qmqm.pl>,
Nicholas Piggin <npiggin@...il.com>,
Nicolas Palix <nicolas.palix@...g.fr>,
Peter Zijlstra <peterz@...radead.org>,
Rasmus Villemoes <linux@...musvillemoes.dk>,
Matti Vaittinen <Matti.Vaittinen@...rohmeurope.com>,
linux-kernel@...r.kernel.org
Cc: Yury Norov <yury.norov@...il.com>, cocci@...ia.fr
Subject: [PATCH 02/22] introduce cpumask.cocci
Using cpumask_weight() to compare weight of cpumask against a number
or expression is common but wrong pattern. The more efficient way is
to use cpumask_weight_{empty,full,gt,lt,ge,le,eq} as appropriate.
This patch adds cocci script to test sources for this.
CC: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
CC: Julia Lawall <Julia.Lawall@...ia.fr>
CC: Nicolas Palix <nicolas.palix@...g.fr>
CC: Rasmus Villemoes <linux@...musvillemoes.dk>
CC: linux-kernel@...r.kernel.org
CC: cocci@...ia.fr
Signed-off-by: Yury Norov <yury.norov@...il.com>
---
MAINTAINERS | 1 +
scripts/coccinelle/api/cpumask.cocci | 51 ++++++++++++++++++++++++++++
2 files changed, 52 insertions(+)
create mode 100644 scripts/coccinelle/api/cpumask.cocci
diff --git a/MAINTAINERS b/MAINTAINERS
index 17fd10824636..ecd97fdd5d67 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -3524,6 +3524,7 @@ F: lib/find_bit_benchmark.c
F: lib/nodemask.c
F: lib/test_bitmap.c
F: scripts/coccinelle/api/bitmap.cocci
+F: scripts/coccinelle/api/cpumask.cocci
F: tools/include/linux/bitmap.h
F: tools/include/linux/find.h
F: tools/lib/bitmap.c
diff --git a/scripts/coccinelle/api/cpumask.cocci b/scripts/coccinelle/api/cpumask.cocci
new file mode 100644
index 000000000000..2eb930dbe9c4
--- /dev/null
+++ b/scripts/coccinelle/api/cpumask.cocci
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/// Use cpumask_empty rather than cpumask_weight() == 0 etc
+///
+// Confidence: High
+// Copyright: (C) 2022 Yury Norov
+// URL: http://coccinelle.lip6.fr/
+// Comments:
+// Options: --no-includes --include-headers
+
+virtual org
+virtual report
+virtual context
+virtual patch
+
+@...pty1 depends on !patch@
+position p;
+statement S;
+@@
+
+if (cpumask_weight@p(...)) S
+
+@...ipt:python depends on report@
+p << rempty1.p;
+@@
+
+for p0 in p:
+ coccilib.report.print_report(p0, "ERROR: use !cpumask_empty()")
+
+@...ipt:python depends on org@
+p << rempty1.p;
+@@
+
+@...p depends on !patch@
+expression exp;
+binary operator cmp = {>, <, >=, <=, ==, !=};
+position p;
+@@
+
+ cpumask_weight(...) cmp@p exp
+
+@...ipt:python depends on report@
+p << rcmp.p;
+@@
+
+for p0 in p:
+ coccilib.report.print_report(p0,
+ "ERROR: use cpumask_weight_{empty,full,gt,lt,ge,le,eq} as appropriate")
+
+@...ipt:python depends on org@
+p << rcmp.p;
+@@
--
2.32.0
Powered by blists - more mailing lists