Re: [Cocci] Match variable declaration with init expression

2020-07-31 Thread Julia Lawall



On Fri, 31 Jul 2020, Denis Efremov wrote:

> Hi,
>
> This pattern:
> - E = kzalloc(size, flags | __GFP_NOWARN);
> - if (\(!E\|E == null\))@p
> -   E = vzalloc(size);
> + E = kvzalloc(size, flags);
>
> matches this code:
> void *p;
> p = kzalloc(size, gfp | __GFP_NOWARN);
>
> if (!p)
>   p = vzalloc(size);
>
> But not this:
> void *p = kzalloc(size, gfp | __GFP_NOWARN);
>
> if (!p)
>   p = vzalloc(size);
>
> What can I do to match them both?

For a transformation like that, it's not possible to match both at once.
The problem is that it doesn't know what you want to do with E.  You can't
remove it and just leave void alone.

I don't know if a disjunction is possible either, because one is a
declaration and the other is a statement.

julia
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci


[Cocci] Match variable declaration with init expression

2020-07-31 Thread Denis Efremov
Hi,

This pattern:
- E = kzalloc(size, flags | __GFP_NOWARN);
- if (\(!E\|E == null\))@p
-   E = vzalloc(size);
+ E = kvzalloc(size, flags);

matches this code:
void *p;
p = kzalloc(size, gfp | __GFP_NOWARN);

if (!p)
p = vzalloc(size);

But not this:
void *p = kzalloc(size, gfp | __GFP_NOWARN);

if (!p)
p = vzalloc(size);

What can I do to match them both?

Thanks,
Denis
___
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci