[Cocci] strange behaviour, failing to insert expression in valid C source file

Leif Lindholm leif.lindholm at linaro.org
Wed Nov 26 16:07:28 CET 2014


Hi there,

I was asked to change an API in the Linux kernel by adding an optional
parameter in form of a pointer. So I reached for coccinelle to add
", NULL" to all existing callers. To do so, I used the following sp-file:
---
@@
expression E1;
@@

- of_find_node_by_path(E1)
+ of_find_node_by_path(E1, NULL)
---

This worked splendidly on all call sites in the kernel, except for two
in the of_resolve_phandles() function in drivers/of/resolver.c.
It looks like spatch becomes upset on encountering a variable with the
same name as an autodetected typedef. This can be confirmed with
--parse-c.

I've reduced my test case to the following:
---
phandle of_get_tree_max_phandle(void)
{
    return NULL;
}

void bar(void)
{
    struct device_node *node;
    phandle phandle;

    node = of_find_node_by_path("/__symbols__");
}
---

Running the command:
spatch --in-place --sp-file ../of.cocci foo.c
fails silently to update the file, and returns 0.

Tested on 1.0.0-rc22 and -rc12.

Thanks,

Leif


More information about the Cocci mailing list