Hello,

After seeing this patch http://permalink.gmane.org/gmane.linux.kernel.commits.head/348204 I tried to write a semantic patch that ensures that a call to d_find_alias() is followed by a call to dput().

The attached patch seems to do that. I wrote it by copying the example found in the "Reference counter: the of_xxx API" paragraph of the grammar. I haven't played with Coccinelle in a while though, and I can't remember exactly the semantics of the "exists" keyword and of the "<... ...>" and "<+... ...+>". Could you enlighten me ?

If the patch looks good to you, I'll send it to kernel-janitors (unless there is a more approriate list for semantic patches) along with a few patches.


WBR,
Cyril Roelandt.
//
// Make sure calls to d_find_alias() have a corresponding call to dput().
//
// Keywords: d_find_alias, dput
//

virtual context
virtual org
virtual patch
virtual report

@initialize:python depends on org || report@
msg = "Missing call to dput() at line %s."

@r exists@
local idexpression struct dentry *dent;
expression E, E1;
statement S1, S2;
position p1, p2;
@@
(
        if (!(dent@p1 = d_find_alias(...))) S1
|
        dent@p1 = d_find_alias(...)
)

<...when != dput(dent)
    when != if (...) { <+... dput(dent) ...+> }
    when != true !dent || ...
    when != dent = E
    when != E = dent
if (!dent || ...) S2
...>
(
        return <+...dent...+>;
|
        return @p2 ...;
|
        dent = E1;
|
        E1 = dent;
)

@depends on context@
local idexpression struct dentry *r.dent;
position r.p1;
@@
* dent@p1 = ...;

@script:python depends on org@
p1 << r.p1;
p2 << r.p2;
@@
coccilib.org.print_todo(p1[0],  msg % (p2[0].line))

@depends on r && patch@
local idexpression struct dentry *r.dent;
position r.p2;
@@
+ dput(dent);
  return @p2 ...;

@script:python depends on report@
p1 << r.p1;
p2 << r.p2;
@@
coccilib.report.print_report(p1[0], msg % (p2[0].line))
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to