lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220510154750.212913-4-yury.norov@gmail.com>
Date:   Tue, 10 May 2022 08:47:31 -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 03/22] introduce nodemask.cocci

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@...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/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
+
+@...pty1 depends on !patch@
+position p;
+statement S;
+@@
+
+if (nodes_weight@p(...)) S
+
+@...ipt:python depends on report@
+p << rempty1.p;
+@@
+
+for p0 in p:
+        coccilib.report.print_report(p0, "ERROR: use !nodes_empty()")
+
+@...ipt:python depends on org@
+p << rempty1.p;
+@@
+
+@...p depends on !patch@
+expression exp;
+binary operator cmp = {>, <, >=, <=, ==, !=};
+position p;
+@@
+
+ nodes_weight(...) cmp@p exp
+
+@...ipt: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")
+
+@...ipt:python depends on org@
+p << rcmp.p;
+@@
-- 
2.32.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ