scripts: coccinelle: devm_free: reduce false positives
authorJulia Lawall <Julia.Lawall@inria.fr>
Sun, 9 Aug 2026 16:43:36 +0000 (18:43 +0200)
committerJulia Lawall <Julia.Lawall@inria.fr>
Sun, 23 Aug 2026 20:12:10 +0000 (22:12 +0200)
False positives could be introduced due to allocations using the new
_obj functions.  Add these to the "safe" rule accordingly.

False positives could also be introduced when the same variable
name has two possible types.  Incorporate type information to avoid
reporting this case  This does lead to false negatives when no type
information is available.

Signed-off-by: Julia Lawall <Julia.Lawall@inria.fr>
Reported-by: Ricardo Ribalda <ribalda@chromium.org>
scripts/coccinelle/free/devm_free.cocci

index 0880729..947d7e6 100644 (file)
@@ -26,7 +26,8 @@ virtual report
 virtual context
 
 @r depends on context || org || report@
-expression x;
+type T;
+T x;
 @@
 
 (
@@ -56,18 +57,26 @@ expression x;
 )
 
 @safe depends on context || org || report exists@
-expression x;
+r.T x;
 position p;
 @@
 
 (
  x = kmalloc(...)
+|
+ x = kmalloc_obj(...)
+|
+ x = kmalloc_objs(...)
 |
  x = kvasprintf(...)
 |
  x = kasprintf(...)
 |
  x = kzalloc(...)
+|
+ x = kzalloc_obj(...)
+|
+ x = kzalloc_objs(...)
 |
  x = kmalloc_array(...)
 |
@@ -105,7 +114,7 @@ position p;
 )
 
 @pb@
-expression r.x;
+r.T r.x;
 position p != safe.p;
 @@