Skip to contentSkip to conversation

Match variable declaration with init expression

Cocci Denis Efremov 2 participants 2 messages Jul 31, 2020

lore
Share & tools
lore
#0 lore raw

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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

#1 lore raw
Quoted 15 lines · 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);
Quoted 7 lines

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
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci