Coccinelle Archive on lore.kernel.org
 help / color / Atom feed
* [Cocci] Match variable declaration with init expression
@ 2020-07-31 12:40 Denis Efremov
  2020-07-31 16:55 ` Julia Lawall
  0 siblings, 1 reply; 2+ messages in thread
From: Denis Efremov @ 2020-07-31 12:40 UTC (permalink / raw)
  To: cocci

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Cocci] Match variable declaration with init expression
  2020-07-31 12:40 [Cocci] Match variable declaration with init expression Denis Efremov
@ 2020-07-31 16:55 ` Julia Lawall
  0 siblings, 0 replies; 2+ messages in thread
From: Julia Lawall @ 2020-07-31 16:55 UTC (permalink / raw)
  To: Denis Efremov; +Cc: cocci



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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-31 12:40 [Cocci] Match variable declaration with init expression Denis Efremov
2020-07-31 16:55 ` Julia Lawall

Coccinelle Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cocci/0 cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ https://lore.kernel.org/cocci \
		cocci@systeme.lip6.fr
	public-inbox-index cocci

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/fr.lip6.systeme.cocci


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git