public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] coccinelle: Add str_off_on() and str_no_yes() rules
@ 2024-10-27 12:58 Thorsten Blum
  2024-10-27 15:06 ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2024-10-27 12:58 UTC (permalink / raw)
  To: Kees Cook, Andy Shevchenko, Julia Lawall, Nicolas Palix
  Cc: Thorsten Blum, linux-hardening, cocci, linux-kernel

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] coccinelle: Add str_off_on() and str_no_yes() rules
  2024-10-27 12:58 [PATCH] coccinelle: Add str_off_on() and str_no_yes() rules Thorsten Blum
@ 2024-10-27 15:06 ` Andy Shevchenko
  2024-10-27 15:25   ` Julia Lawall
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2024-10-27 15:06 UTC (permalink / raw)
  To: Thorsten Blum
  Cc: Kees Cook, Andy Shevchenko, Julia Lawall, Nicolas Palix,
	linux-hardening, cocci, linux-kernel

On Sun, Oct 27, 2024 at 2:59 PM Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> In addition to str_on_off() and str_yes_no(), add rules to search for
> str_off_on() and str_no_yes() replacements.

I don't know cocci well enough, but this does simply not scale. We
also have cases where "Yes"/"No", "YES"/"NO" and all possible
variations of that.


-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] coccinelle: Add str_off_on() and str_no_yes() rules
  2024-10-27 15:06 ` Andy Shevchenko
@ 2024-10-27 15:25   ` Julia Lawall
  2024-10-27 18:56     ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Julia Lawall @ 2024-10-27 15:25 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Thorsten Blum, Kees Cook, Andy Shevchenko, Nicolas Palix,
	linux-hardening, cocci, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 655 bytes --]



On Sun, 27 Oct 2024, Andy Shevchenko wrote:

> On Sun, Oct 27, 2024 at 2:59 PM Thorsten Blum <thorsten.blum@linux.dev> wrote:
> >
> > In addition to str_on_off() and str_yes_no(), add rules to search for
> > str_off_on() and str_no_yes() replacements.
>
> I don't know cocci well enough, but this does simply not scale. We
> also have cases where "Yes"/"No", "YES"/"NO" and all possible
> variations of that.

Andy, are you concerned about the number of such functions in the kernel
or the number of rules in the semantic patch.  There are indeed more
concise ways to write the semantic patch.

julia

>
>
> --
> With Best Regards,
> Andy Shevchenko
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] coccinelle: Add str_off_on() and str_no_yes() rules
  2024-10-27 15:25   ` Julia Lawall
@ 2024-10-27 18:56     ` Andy Shevchenko
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2024-10-27 18:56 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Thorsten Blum, Kees Cook, Andy Shevchenko, Nicolas Palix,
	linux-hardening, cocci, linux-kernel

On Sun, Oct 27, 2024 at 5:25 PM Julia Lawall <julia.lawall@inria.fr> wrote:
> On Sun, 27 Oct 2024, Andy Shevchenko wrote:
> > On Sun, Oct 27, 2024 at 2:59 PM Thorsten Blum <thorsten.blum@linux.dev> wrote:
> > >
> > > In addition to str_on_off() and str_yes_no(), add rules to search for
> > > str_off_on() and str_no_yes() replacements.
> >
> > I don't know cocci well enough, but this does simply not scale. We
> > also have cases where "Yes"/"No", "YES"/"NO" and all possible
> > variations of that.
>
> Andy, are you concerned about the number of such functions in the kernel
> or the number of rules in the semantic patch.

Rules for the semantic patches I am worried about.

>  There are indeed more
> concise ways to write the semantic patch.

Would be nice to see ways to cover more cases in less lines in the spatch.


-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-10-27 18:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-27 12:58 [PATCH] coccinelle: Add str_off_on() and str_no_yes() rules Thorsten Blum
2024-10-27 15:06 ` Andy Shevchenko
2024-10-27 15:25   ` Julia Lawall
2024-10-27 18:56     ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox