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?

Your example works fine here when I pass -all_includes:

@@ -4,9 +4,9 @@
 extern struct task_struct *t;
 void context(void)
 {
-       if (t->pid)
+       if (!is_idle_task(t))
                do_something();
-       if (current->pid)
+       if (!is_idle_task(current))
                do_something();
 }

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

Reply via email to