From: Thorsten Blum <thorsten.blum@linux.dev>
To: Kees Cook <kees@kernel.org>, Andy Shevchenko <andy@kernel.org>,
Julia Lawall <Julia.Lawall@inria.fr>,
Nicolas Palix <nicolas.palix@imag.fr>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
linux-hardening@vger.kernel.org, cocci@inria.fr,
linux-kernel@vger.kernel.org
Subject: [PATCH] coccinelle: Add str_off_on() and str_no_yes() rules
Date: Sun, 27 Oct 2024 13:58:59 +0100 [thread overview]
Message-ID: <20241027125858.1804-2-thorsten.blum@linux.dev> (raw)
In addition to str_on_off() and str_yes_no(), add rules to search for
str_off_on() and str_no_yes() replacements.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
scripts/coccinelle/api/string_choices.cocci | 38 +++++++++++++++++++++
1 file changed, 38 insertions(+)
diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci
index 375045086912..93de05aeded2 100644
--- a/scripts/coccinelle/api/string_choices.cocci
+++ b/scripts/coccinelle/api/string_choices.cocci
@@ -282,6 +282,25 @@ e << str_on_off_r.E;
coccilib.report.print_report(p[0], "opportunity for str_on_off(%s)" % e)
+@str_off_on depends on patch@
+expression E;
+@@
+- ((E) ? "off" : "on")
++ str_off_on(E)
+
+@str_off_on_r depends on !patch@
+expression E;
+position P;
+@@
+* E@P ? "off" : "on"
+
+@script:python depends on report@
+p << str_off_on_r.P;
+e << str_off_on_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_off_on(%s)" % e)
+
@str_yes_no depends on patch@
expression E;
@@
@@ -300,3 +319,22 @@ e << str_yes_no_r.E;
@@
coccilib.report.print_report(p[0], "opportunity for str_yes_no(%s)" % e)
+
+@str_no_yes depends on patch@
+expression E;
+@@
+- ((E) ? "no" : "yes")
++ str_no_yes(E)
+
+@str_no_yes_r depends on !patch@
+expression E;
+position P;
+@@
+* E@P ? "no" : "yes"
+
+@script:python depends on report@
+p << str_no_yes_r.P;
+e << str_no_yes_r.E;
+@@
+
+coccilib.report.print_report(p[0], "opportunity for str_no_yes(%s)" % e)
--
2.47.0
next reply other threads:[~2024-10-27 12:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-27 12:58 Thorsten Blum [this message]
2024-10-27 15:06 ` [PATCH] coccinelle: Add str_off_on() and str_no_yes() rules Andy Shevchenko
2024-10-27 15:25 ` Julia Lawall
2024-10-27 18:56 ` Andy Shevchenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241027125858.1804-2-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=Julia.Lawall@inria.fr \
--cc=andy@kernel.org \
--cc=cocci@inria.fr \
--cc=kees@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nicolas.palix@imag.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox