On Wed, Dec 14, 2011 at 08:34:26PM +0100, Lars-Peter Clausen wrote:
> On 12/14/2011 08:29 PM, Lars-Peter Clausen wrote:
> > On 12/14/2011 08:08 PM, Josh Triplett wrote:
> >> In the Linux kernel, "current" refers to the current task, of type
> >> "struct task_struct *", by way of a stack of (sometimes arch-specific)
> >> macros.  For instance, arch/x86/include/asm/current.h defines current as
> >> get_current(), an inline function returning "struct task_struct *".
> >> Other architectures, as well as asm-generic, use variations on the same
> >> theme with varying depths of macros.
> >>
> >> However, coccinelle doesn't seem to manage to figure out the type of
> >> current, because rules defined with @@struct task_struct *task;@@ don't
> >> match current.
> >>
> >> I can work around this by writing a duplicate set of rules with
> >> @@identifier current;@@, but I'd rather not have to introduce that
> >> duplication.
> >>
> >> For a test case, try the following semantic patch:
> >>
> >> @@ struct task_struct *task; @@
> >> - (task)->pid == 0
> >> + is_idle_task(task)
> >>
> >> @@ struct task_struct *task; @@
> >> - (task)->pid != 0
> >> + !is_idle_task(task)
> >>
> >>
> >> And the following test file:
> >>
> >> #include <linux/sched.h>
> >> extern struct task_struct *t;
> >> void context(void)
> >> {
> >>         if (t->pid)
> >>            do_something();
> >>         if (current->pid)
> >>            do_something();
> >> }
> >>
> >>
> >> Coccinelle successfully patches the first condition, but not the second.
> > 
> > Did you ran spatch with -all_includes?
> 
> Sorry, make that -recursive_includes.

Good to know.  "make coccicheck" in the Linux kernel doesn't currently
use either of those two options; should it?

- Josh Triplett
_______________________________________________
Cocci mailing list
[email protected]
http://lists.diku.dk/mailman/listinfo/cocci
(Web access from inside DIKUs LAN only)

Reply via email to