devm as drm-init arg: rule with expression finds less than rule with identifier
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
Oleg Petrov писал(а) 2025-09-05 17:06:
Quoted 48 lines
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
Quoted 8 lines
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
Quoted 2 lines
I wonder, why is that the case? As I understand it, identifier itself should match expression.
The software combination “Coccinelle 1.3.0” does also not produce an expected difference display by the following SmPL script variant according to the implementation of the function “tilcdc_crtc_create”.
https://elixir.bootlin.com/linux/v6.17-rc7/source/drivers/gpu/drm/tilcdc/tilcdc_crtc.c#L1017-L1076
@badarg2@
position p, q, r;
expression devm, e, local;
@@
*devm =@p devm_kzalloc(...);
...
*local =@r <+... devm ...+>;
...
*drm_crtc_init_with_planes(@q e, <+... local ...+>, ...)
How will the software be improved further?
Regards,
Markus