Coccinelle archive mirror
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@inria.fr>
To: Hongbo Li <lihongbo22@huawei.com>
Cc: kees@kernel.org, andy@kernel.org, nicolas.palix@imag.fr,
	 linux-hardening@vger.kernel.org, cocci@inria.fr
Subject: Re: [cocci] [PATCH -next v2 1/9] coccinelle: Add rules to find str_true_false() replacements
Date: Mon, 9 Sep 2024 18:00:29 +0200 (CEST)	[thread overview]
Message-ID: <71436945-5386-ff6e-8e8c-b513d4509241@inria.fr> (raw)
In-Reply-To: <20240904091451.3328272-2-lihongbo22@huawei.com>



On Wed, 4 Sep 2024, Hongbo Li wrote:

> After str_true_false() has been introduced in the tree,
> we can add rules for finding places where str_true_false()
> can be used. A simple test can find over 10 locations.
>
> Signed-off-by: Hongbo Li <lihongbo22@huawei.com>
> ---
>  scripts/coccinelle/api/string_choices.cocci | 23 +++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>
> diff --git a/scripts/coccinelle/api/string_choices.cocci b/scripts/coccinelle/api/string_choices.cocci
> index 5e729f187f22..50329c4c8acd 100644
> --- a/scripts/coccinelle/api/string_choices.cocci
> +++ b/scripts/coccinelle/api/string_choices.cocci
> @@ -85,3 +85,26 @@ e << str_down_up_r.E;
>  @@
>
>  coccilib.report.print_report(p[0], "opportunity for str_down_up(%s)" % e)
> +
> +@str_true_false depends on patch@
> +expression E;
> +@@
> +(

There is no need for the above.  That is only needed if there is a
disjunction, ie a set of possible changes.  Likewise no need for the ),
and the same in the next rule.

julia

> +-      ((E) ? "true" : "false")
> ++      str_true_false(E)
> +)
> +
> +@str_true_false_r depends on !patch exists@
> +expression E;
> +position P;
> +@@
> +(
> +*      ((E@P) ? "true" : "false")
> +)
> +
> +@script:python depends on report@
> +p << str_true_false_r.P;
> +e << str_true_false_r.E;
> +@@
> +
> +coccilib.report.print_report(p[0], "opportunity for str_true_false(%s)" % e)
> --
> 2.34.1
>
>

       reply	other threads:[~2024-09-09 16:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240904091451.3328272-1-lihongbo22@huawei.com>
     [not found] ` <20240904091451.3328272-2-lihongbo22@huawei.com>
2024-09-09 16:00   ` Julia Lawall [this message]
2024-09-09 16:03 ` [cocci] [PATCH -next v2 0/9] coccinelle: Add some rules for string_chioces helpers Julia Lawall

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=71436945-5386-ff6e-8e8c-b513d4509241@inria.fr \
    --to=julia.lawall@inria.fr \
    --cc=andy@kernel.org \
    --cc=cocci@inria.fr \
    --cc=kees@kernel.org \
    --cc=lihongbo22@huawei.com \
    --cc=linux-hardening@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).