* [PATCH v2] cocci: Add rules to find str_plural() replacements
@ 2024-02-15 19:48 Kees Cook
2024-02-16 12:03 ` [cocci] " Markus Elfring
0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2024-02-15 19:48 UTC (permalink / raw)
To: Michal Wajdeczko
Cc: Kees Cook, Jani Nikula, Andy Shevchenko, Julia Lawall,
Nicolas Palix, cocci, Andy Shevchenko, linux-kernel,
linux-hardening
Add rules for finding places where str_plural() can be used. This
currently finds:
54 files changed, 62 insertions(+), 61 deletions(-)
Co-developed-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Signed-off-by: Michal Wajdeczko <michal.wajdeczko@intel.com>
Link: https://lore.kernel.org/all/fc1b25a8-6381-47c2-831c-ab6b8201a82b@intel.com/
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Cc: Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Julia Lawall <Julia.Lawall@inria.fr>
Cc: Nicolas Palix <nicolas.palix@imag.fr>
Cc: cocci@inria.fr
---
MAINTAINERS | 1 +
scripts/coccinelle/api/string_choices.cocci | 41 +++++++++++++++++++++
2 files changed, 42 insertions(+)
create mode 100644 scripts/coccinelle/api/string_choices.cocci
diff --git a/MAINTAINERS b/MAINTAINERS
index d0df728734c1..216d02a3fed5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8979,6 +8979,7 @@ F: lib/string.c
F: lib/string_helpers.c
F: lib/test-string_helpers.c
F: lib/test_string.c
+F: scripts/coccinelle/api/string_choices.cocci
GENERIC UIO DRIVER FOR PCI DEVICES
M: "Michael S. Tsirkin" <mst@redhat.com>
diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci
new file mode 100644
index 000000000000..a71966c0494e
--- /dev/null
+++ b/scripts/coccinelle/api/string_choices.cocci
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/// Find places to use string_choices.h's various helpers.
+//
+// Confidence: Medium
+// Options: --no-includes --include-headers
+virtual patch
+virtual context
+virtual report
+
+@str_plural depends on patch@
+expression E;
+@@
+(
+- ((E == 1) ? "" : "s")
++ str_plural(E)
+|
+- ((E != 1) ? "s" : "")
++ str_plural(E)
+|
+- ((E > 1) ? "s" : "")
++ str_plural(E)
+)
+
+@str_plural_r depends on !patch exists@
+expression E;
+position P;
+@@
+(
+* ((E@P == 1) ? "" : "s")
+|
+* ((E@P != 1) ? "s" : "")
+|
+* ((E@P > 1) ? "s" : "")
+)
+
+@script:python depends on report@
+p << str_plural_r.P;
+e << str_plural_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_plural(%s)" % e)
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [cocci] [PATCH v2] cocci: Add rules to find str_plural() replacements
2024-02-15 19:48 [PATCH v2] cocci: Add rules to find str_plural() replacements Kees Cook
@ 2024-02-16 12:03 ` Markus Elfring
0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2024-02-16 12:03 UTC (permalink / raw)
To: Kees Cook, Michal Wajdeczko, cocci, kernel-janitors
Cc: LKML, Andy Shevchenko, Andy Shevchenko, Jani Nikula,
Julia Lawall, Nicolas Palix, linux-hardening
> Add rules for finding places where str_plural() can be used.
…
> +++ b/scripts/coccinelle/api/string_choices.cocci
> @@ -0,0 +1,41 @@
…
> +/// Find places to use string_choices.h's various helpers.
> +//
> +// Confidence: Medium
> +// Options: --no-includes --include-headers
> +virtual patch
> +virtual context
> +virtual report
Would you like to support another operation mode?
virtual context, patch, report, org
Regards,
Markus
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-16 12:04 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-15 19:48 [PATCH v2] cocci: Add rules to find str_plural() replacements Kees Cook
2024-02-16 12:03 ` [cocci] " Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).