[cocci mailing list added in CC]
On Wed, 1 Sep 2010, Paul E. McKenney wrote:
> On Wed, Sep 01, 2010 at 09:44:23AM -0700, Paul E. McKenney wrote:
> > On Wed, Sep 01, 2010 at 08:06:18AM +0200, Julia Lawall wrote:
>
> [ . . . ]
>
> > Hmmmm... I am getting hit by loops:
> >
> > diff =
> > --- drivers/net/cnic.c 2010-08-16 11:54:39.000000000 -0700
> > @@ -2101,13 +2101,10 @@ static void service_kcqes(struct cnic_de
> > goto end;
> > }
> >
> > - rcu_read_lock();
> > - ulp_ops = rcu_dereference(cp->ulp_ops[ulp_type]);
> > if (likely(ulp_ops)) {
> > - ulp_ops->indicate_kcqes(cp->ulp_handle[ulp_type],
> > cp->completed_kcq + i, j);
> > }
> > - rcu_read_unlock();
> > end:
> > num_cqes -= j;
> > i += j;
> >
> >
> > It took me a bit to figure out that the complaint was due to the fact
> > that the above code is within a loop. ;-)
>
> And the obvious fix is to do "... when != p = e2" -- sorry for not
> figuring this out to start with!!!
Since p is an identifier, this is indeed good enough. Sometimes, however,
you are interested in an arbitrary expression, and the loop can update a
subexpression of this expression. For example, if you are interested in
double calls to a function foo with the same argument, you could write:
@@
expression E;
expression E1;
@@
foo(E)
... when != E = E1
foo(E)
But this is not good enough to avoid, eg:
for(i=0;i!=19;i++) foo(x[i]);
The problem can be solved with two rules:
@r@
expression E;
@@
foo(E)
@@
expression r.E;
expression E1;
expression subE <= r.E;
@@
foo(E)
... when != subE = E1
foo(E)
subE matches any subexpression of r.E. Unfortunately, to keep the
implementation reasonably simple, this only works when the right argument
of <= is already bound, which is why two rules are needed.
julia
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)