projects/linux·commit e71ec0bc

scripts: coccinelle: allow list_entry_is_head() to use pos

e71ec0bc · Daniel Thompson <[email protected]> · 2021-07-30 10:58:56 +01:00

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.

Signed-off-by: Daniel Thompson <[email protected]>
Signed-off-by: Julia Lawall <[email protected]>
Commit
e71ec0bc06038cdfa18cbd23f5cea71fe4785d35
Parents
9eec0792

Changes

1 files changed · +2 −0

FileStatusAddDelContent
scripts/coccinelle/iterators/use_after_iter.coccimodified+2−0View file

scripts/coccinelle/iterators/use_after_iter.cocci

View file
diff --git a/scripts/coccinelle/iterators/use_after_iter.cocci b/scripts/coccinelle/iterators/use_after_iter.cocci
index 9be48b5..676edd5 100644
--- a/scripts/coccinelle/iterators/use_after_iter.cocci
+++ b/scripts/coccinelle/iterators/use_after_iter.cocci
@@ -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