On Tue, 12 Mar 2019, Maxime Ripard wrote:
> On Tue, Mar 12, 2019 at 10:03:57AM +0100, Julia Lawall wrote:
> > >
> > > @@
> > > identifier fb;
> > > @@
> > > ...
> > > struct drm_framebuffer *fb;
> > > ...
> > > - drm_format_num_planes(fb->format->format)
> > > + fb->format->num_planes
> > >
> > > // This one seems to work properly
> >
> > How about:
> >
> > @@
> > struct drm_framebuffer *fb;
> > @@
> >
> > - drm_format_num_planes(fb->format->format)
> > + fb->format->num_planes
> >
> > That is, you don't need to insist on there being a local variable
> > declaration, you just want an expression of the right type. This will
> > also be much more efficient.
>
> I have an extra question on that one. Are function parameters also
> considered expressions with that syntax?
>
> Let's say for example, I want to replace the call to drm_format_info
> by drm_get_format_info in that function:
> https://elixir.bootlin.com/linux/v5.0/source/drivers/gpu/drm/omapdrm/omap_fb.c#L340
>
> That snippet doesn't work:
> @@
> struct drm_device *dev;
> struct drm_mode_fb_cmd2 *cmd;
> @@
>
> - drm_format_info(cmd->pixel_format)
> + drm_get_format_info(dev, cmd)
>
> with spatch producing the following warnings and errors:
>
> warning: rule starting on line 1: metavariable dev not used in the - or
> context code
> error: rule starting on line 1: dev appears only in + code
>
> Does that mean I have to explicitly have the function prototype as
> context?
It has nothing to do with function parameters. You have plus code that
refers to a metavariable (dev) that doesn't appear in the - code. So
Coccinelle has no idea what you want it to be.
There is no shortcut to match both a local variable and a function
parameter. You need to have a specific rule matching the form of the
function:
f(...,struct drm_device *dev,...) {
<+...
- drm_format_info(cmd->pixel_format)
+ drm_get_format_info(dev, cmd)
...+>
}
You could use either <... ...> or <+... ...+>. <+... ...+> indicates that
a call to drm_format_info is required, which will cause Coccinele to
mostly skip processing of functions that don't contain it.
julia
_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci