From: Oleg Petrov <o.petrov@ispras.ru>
To: cocci@inria.fr
Subject: Re: [cocci] devm as drm-init arg: rule with expression finds less than rule with identifier
Date: Tue, 23 Sep 2025 12:23:10 +0300 [thread overview]
Message-ID: <c889f5f9194fa940b18a9a951b7b1de4@ispras.ru> (raw)
In-Reply-To: <3addf44d4f2524588d664102d5109aad@ispras.ru>
Oleg Petrov писал(а) 2025-09-05 17:06:
> Hello,
>
> TLDR A rule finds a match with identifier, but not with expression.
>
> I'm using Coccinelle to search for devres-allocated arguments for
> drm*init functions. I have a simple rule which seems to work fine:
>
> @badarg exists@
> position p,q;
> expression devm,e;
> @@
>
> devm =@p devm_kzalloc(...);
> ...
> drm_crtc_init_with_planes(@q e,<+...devm...+>,...)
>
> @script:python@
> p << badarg.p;
> q << badarg.q;
> @@
> print(p[0].file + ":" + p[0].line + "," + q[0].line)
>
> But then I'd like to find a similar thing, but when another
> intermediate variable is used somehow:
>
> @badarg2 exists@
> position p,q,r;
> expression devm,e;
> identifier local;
> @@
>
> devm =@p devm_kzalloc(...);
> ...
> local =@r <+...devm...+>;
> ...
> drm_crtc_init_with_planes (@q e,<+...local...+>,...)
>
> @script:python@
> p << badarg2.p;
> q << badarg2.q;
> r << badarg2.r;
> @@
> print(p[0].file + ":" + p[0].line + "," + r[0].line + "," + q[0].line)
>
> This last rule finds two matches:
> drivers/gpu/drm/tilcdc/tilcdc_crtc.c:1005,1018,1031
> drivers/gpu/drm/meson/meson_crtc.c:680,686,687
>
> But if I change local to be expression, the rule finds only
> drivers/gpu/drm/meson/meson_crtc.c:680,686,687
>
> I wonder, why is that the case? As I understand it, identifier itself
> should match expression.
>
> Best regards,
> Oleg
I guess I messed up sending the email earlier. I'll add the versions
then:
spatch is 1.1.1 and the results should be the same for Linux 5.10+.
My command line:
spatch --sp-file local_name.cocci --dir drivers/gpu/drm --very-quiet
next prev parent reply other threads:[~2025-09-23 9:23 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-05 14:06 [cocci] devm as drm-init arg: rule with expression finds less than rule with identifier Oleg Petrov
2025-09-23 9:23 ` Oleg Petrov [this message]
2025-09-23 13:07 ` Markus Elfring
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=c889f5f9194fa940b18a9a951b7b1de4@ispras.ru \
--to=o.petrov@ispras.ru \
--cc=cocci@inria.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).