On Wed, 14 Dec 2011, 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

identifier current; would not be right at all, because it would match any identifier. The choices are only either to make an explicit rule for current or to use strong enough include options so that coccinelle can find the type itself. You can try -all_includes or for even more include files -recursive_includes. But this will slow down a lot your processing time. On the other hand, you probably need at least all_includes to get the types of structure fields.

julia

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.

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

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

Reply via email to