Re: [Cocci] [PATCH V2] coccinelle: iterators: Add for_each_child.cocci script

From: Julia Lawall
Date: Tue Oct 13 2020 - 06:30:40 EST


I have one more change to suggest. This one only affects the patch case,
as the other cases just point to a problem but don't ompletely specify
what to do about it.

> +@ruleone depends on patch && !context && !org && !report@
> +
> +local idexpression r.n;
> +iterator r.i,i1;
> +expression e;
> +expression list [r.n1] es;
> +statement S;
> +@@
> +
> + i(es,n,...) {
> + ...
> +(
> + of_node_put(n);
> +|
> + e = n
> +|
> + return n;
> +|
> + i1(...,n,...) S
> +|
> ++ of_node_put(n);
> +? return ...;
> +)
> + ... when any
> + }

There is one occurrence of the following code:

for_each_available_child_of_node(search, child) {
name = of_get_property(child, "regulator-compatible", NULL);
if (!name)
name = child->name;

if (!strcmp(desc->of_match, name)) {
of_node_put(search);
return of_node_get(child);
}
}

In this case, the for_each_available_child_of_node has incremented the
reference count of child by 1, and then the return increments it again.
It would be ok to put an of_not_put before the return, which is done by
the above rule, but the code would be even simpler if it would just leave
the reference count as is. So before the current return case, you can put
another return case that does the following:

- return of_node_get(n);
+ return n;

julia