scripts: coccinelle: allow list_entry_is_head() to use pos
PATCH 1/1 scripts: coccinelle: allow list_entry_is_head() to use pos
Currently use_after_iter.cocci generates false positives for code of the following form:
~~~
list_for_each_entry(d, &ddata->irq_list, node) {
if (irq == d->irq)
break;
}
if (list_entry_is_head(d, &ddata->irq_list, node))
return IRQ_NONE;~~~
[This specific example comes from drivers/power/supply/cpcap-battery.c]
Most list macros use list_entry_is_head() as loop exit condition meaning it is not unsafe to reuse pos (a.k.a. d) in the code above.
Let's avoid reporting these cases.
---
Notes:
I'm pretty much a complete beginner w.r.t. SmPL. This is written entirely by finding previous fixes and emulating them!
However I did test it by running the checker across the current kernel tree. The changes reduced the error count by four... which was small enough for me to eyeball each one and check they match the pattern I was targetting.
scripts/coccinelle/iterators/use_after_iter.cocci | 2 ++ 1 file changed, 2 insertions(+)
scripts/coccinelle/iterators/use_after_iter.cocci +2 -0
@@ -123,6 +123,8 @@ hlist_for_each_entry_safe(c,...) S | list_remove_head(x,c,...) | +list_entry_is_head(c,...) +| sizeof(<+...c...+>) | &c->member
base-commit: 2734d6c1b1a089fb593ef6a23d4b70903526fe0c --
2.30.2
Julia Lawall
maintainerQuoted 21 lines · Daniel Thompson
Currently
use_after_iter.coccigenerates false positives for code of the following form:
~~~list_for_each_entry(d, &ddata->irq_list, node) { if (irq == d->irq) break; } if (list_entry_is_head(d, &ddata->irq_list, node)) return IRQ_NONE;~~~
[This specific example comes fromdrivers/power/supply/cpcap-battery.c]Most list macros use
list_entry_is_head()as loop exit condition meaning it is not unsafe to reuse pos (a.k.a. d) in the code above.Let's avoid reporting these cases.
Signed-off-by Daniel Thompson <[email protected]>---
Quoted 8 lines
Notes:
I'm pretty much a complete beginner w.r.t. SmPL. This is written entirely by finding previous fixes and emulating them!However I did test it by running the checker across the current kernel tree. The changes reduced the error count by four... which was small enough for me to eyeball each one and check they match the pattern I was targetting.
This looks fine. Thanks for the proposal.
julia
Quoted 23 lines
scripts/coccinelle/iterators/use_after_iter.cocci | 2 ++ 1 file changed, 2 insertions(+)scripts/coccinelle/iterators/use_after_iter.cocci +2
-0@@ -123,6 +123,8 @@ hlist_for_each_entry_safe(c,...) S | list_remove_head(x,c,...) | +list_entry_is_head(c,...) +| sizeof(<+...c...+>) | &c->memberbase-commit:
2734d6c1b1a089fb593ef6a23d4b70903526fe0c--
2.30.2
Quoted 10 lines · Daniel Thompson
Currently
use_after_iter.coccigenerates false positives for code of the following form:
~~~list_for_each_entry(d, &ddata->irq_list, node) { if (irq == d->irq) break; } if (list_entry_is_head(d, &ddata->irq_list, node)) return IRQ_NONE;
Quoted 7 lines
~~~
[This specific example comes fromdrivers/power/supply/cpcap-battery.c]Most list macros use
list_entry_is_head()as loop exit condition meaning it is not unsafe to reuse pos (a.k.a. d) in the code above.Let's avoid reporting these cases.
Applied.
The function is really nice. The use_after_iter.cocci rule gives a lot of false positives where people have used random variables as flags to indicate how the loop was executed...
thanks,
julia
Quoted 35 lines
Signed-off-by Daniel Thompson <[email protected]>---
Notes:
I'm pretty much a complete beginner w.r.t. SmPL. This is written entirely by finding previous fixes and emulating them!However I did test it by running the checker across the current kernel tree. The changes reduced the error count by four... which was small enough for me to eyeball each one and check they match the pattern I was targetting.
scripts/coccinelle/iterators/use_after_iter.cocci | 2 ++ 1 file changed, 2 insertions(+)scripts/coccinelle/iterators/use_after_iter.cocci +2
-0@@ -123,6 +123,8 @@ hlist_for_each_entry_safe(c,...) S | list_remove_head(x,c,...) | +list_entry_is_head(c,...) +| sizeof(<+...c...+>) | &c->memberbase-commit:
2734d6c1b1a089fb593ef6a23d4b70903526fe0c--
2.30.2