All of lore.kernel.org
 help / color / mirror / Atom feed
* [cocci] Matching an if statement with just one func call
@ 2022-05-16 18:34 Phil Edworthy
  2022-05-16 20:21 ` Julia Lawall
  0 siblings, 1 reply; 3+ messages in thread
From: Phil Edworthy @ 2022-05-16 18:34 UTC (permalink / raw)
  To: cocci

Hi,

I'm trying to get my coccinelle test to detect code in
the Linux kernel similar to:
if (!clk)
   clk_disable_unprepare(clk);

So far, I have got:
expression clk;
position p1,p2;
@@

if@p1 ( \( !clk \| clk != NULL \| !IS_ERR(clk) \) )
{ ...
clk_disable_unprepare@p2(clk)
}

However, I don't want to pick up code where something else is covered
by the if statement, such as:
if (!clk) {
   do_something_else;
   clk_disable_unprepare(clk);
}

I know it's related to the ... but I can't get it to work.
Sorry, I'm a coccinelle newbie.

Any help appreciated!

Thanks
Phil

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

* Re: [cocci] Matching an if statement with just one func call
  2022-05-16 18:34 [cocci] Matching an if statement with just one func call Phil Edworthy
@ 2022-05-16 20:21 ` Julia Lawall
  2022-05-17  6:45   ` Phil Edworthy
  0 siblings, 1 reply; 3+ messages in thread
From: Julia Lawall @ 2022-05-16 20:21 UTC (permalink / raw)
  To: Phil Edworthy; +Cc: cocci



On Mon, 16 May 2022, Phil Edworthy wrote:

> Hi,
>
> I'm trying to get my coccinelle test to detect code in
> the Linux kernel similar to:
> if (!clk)
>    clk_disable_unprepare(clk);
>
> So far, I have got:
> expression clk;
> position p1,p2;
> @@
>
> if@p1 ( \( !clk \| clk != NULL \| !IS_ERR(clk) \) )
> { ...

Drop the ...

> clk_disable_unprepare@p2(clk)

Add a ; after the above.

julia

> }
>
> However, I don't want to pick up code where something else is covered
> by the if statement, such as:
> if (!clk) {
>    do_something_else;
>    clk_disable_unprepare(clk);
> }
>
> I know it's related to the ... but I can't get it to work.
> Sorry, I'm a coccinelle newbie.
>
> Any help appreciated!
>
> Thanks
> Phil
>

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

* RE: [cocci] Matching an if statement with just one func call
  2022-05-16 20:21 ` Julia Lawall
@ 2022-05-17  6:45   ` Phil Edworthy
  0 siblings, 0 replies; 3+ messages in thread
From: Phil Edworthy @ 2022-05-17  6:45 UTC (permalink / raw)
  To: Julia Lawall; +Cc: cocci

Simple as that, all working now.
Thanks Julia!

On 16 May 2022 21:22 Julia Lawall wrote:
> On Mon, 16 May 2022, Phil Edworthy wrote:
> 
> > Hi,
> >
> > I'm trying to get my coccinelle test to detect code in the Linux
> > kernel similar to:
> > if (!clk)
> >    clk_disable_unprepare(clk);
> >
> > So far, I have got:
> > expression clk;
> > position p1,p2;
> > @@
> >
> > if@p1 ( \( !clk \| clk != NULL \| !IS_ERR(clk) \) ) { ...
> 
> Drop the ...
> 
> > clk_disable_unprepare@p2(clk)
> 
> Add a ; after the above.
> 
> julia
> 
> > }
> >
> > However, I don't want to pick up code where something else is covered
> > by the if statement, such as:
> > if (!clk) {
> >    do_something_else;
> >    clk_disable_unprepare(clk);
> > }
> >
> > I know it's related to the ... but I can't get it to work.
> > Sorry, I'm a coccinelle newbie.
> >
> > Any help appreciated!
> >
> > Thanks
> > Phil
> >

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

end of thread, other threads:[~2022-05-17  6:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-16 18:34 [cocci] Matching an if statement with just one func call Phil Edworthy
2022-05-16 20:21 ` Julia Lawall
2022-05-17  6:45   ` Phil Edworthy

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.