Messages in this thread Patch in this message | | | From | Yury Norov <> | Subject | [PATCH 03/22] introduce nodemask.cocci | Date | Tue, 10 May 2022 08:47:31 -0700 |
| |
Using nodemask_weight() to compare weight of nodemask against a number or expression is common but wrong pattern. The more efficient way is to use nodemask_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@linux.intel.com> CC: Julia Lawall <Julia.Lawall@inria.fr> CC: Nicolas Palix <nicolas.palix@imag.fr> CC: Rasmus Villemoes <linux@rasmusvillemoes.dk> CC: linux-kernel@vger.kernel.org CC: cocci@inria.fr Signed-off-by: Yury Norov <yury.norov@gmail.com> --- MAINTAINERS | 1 + scripts/coccinelle/api/nodemask.cocci | 51 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 scripts/coccinelle/api/nodemask.cocci
diff --git a/MAINTAINERS b/MAINTAINERS index ecd97fdd5d67..69f95d79e5a3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3525,6 +3525,7 @@ F: lib/nodemask.c F: lib/test_bitmap.c F: scripts/coccinelle/api/bitmap.cocci F: scripts/coccinelle/api/cpumask.cocci +F: scripts/coccinelle/api/nodemask.cocci F: tools/include/linux/bitmap.h F: tools/include/linux/find.h F: tools/lib/bitmap.c diff --git a/scripts/coccinelle/api/nodemask.cocci b/scripts/coccinelle/api/nodemask.cocci new file mode 100644 index 000000000000..1d8578640d97 --- /dev/null +++ b/scripts/coccinelle/api/nodemask.cocci @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0-only +/// Use nodes_empty rather than nodes_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 + +@rempty1 depends on !patch@ +position p; +statement S; +@@ + +if (nodes_weight@p(...)) S + +@script:python depends on report@ +p << rempty1.p; +@@ + +for p0 in p: + coccilib.report.print_report(p0, "ERROR: use !nodes_empty()") + +@script:python depends on org@ +p << rempty1.p; +@@ + +@rcmp depends on !patch@ +expression exp; +binary operator cmp = {>, <, >=, <=, ==, !=}; +position p; +@@ + + nodes_weight(...) cmp@p exp + +@script:python depends on report@ +p << rcmp.p; +@@ + +for p0 in p: + coccilib.report.print_report(p0, + "ERROR: use nodes_weight_{empty,full,gt,lt,ge,le,eq} as appropriate") + +@script:python depends on org@ +p << rcmp.p; +@@ -- 2.32.0
| |