Inspired by some patches sent by Pekka Enberg, eg 958b43384e4.

Signed-off-by: Julia Lawall <[email protected]>

---
 scripts/coccinelle/api/kvfree.cocci |   70 ++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/scripts/coccinelle/api/kvfree.cocci 
b/scripts/coccinelle/api/kvfree.cocci
new file mode 100644
index 0000000..49f8551
--- /dev/null
+++ b/scripts/coccinelle/api/kvfree.cocci
@@ -0,0 +1,70 @@
+/// Use kvfree for choosing free function.
+///
+// Confidence: High
+// Copyright: (C) 2015 Julia Lawall, Inria, GPLv2.
+// URL: http://coccinelle.lip6.fr/
+// Options: --no-includes --include-headers
+
+virtual patch
+virtual context
+virtual org
+virtual report
+
+@r@
+expression e;
+position p;
+@@
+
+if@p (is_vmalloc_addr(e))
+     vfree(e);
+else
+     kfree(e);
+
+@script:python@
+p << r.p;
+@@
+
+if p[0].current_element == "kvfree":
+  cocci.include_match(False)
+
+@s depends on patch && !context && !org && !report@
+expression e;
+position r.p;
+@@
+
+- if@p (is_vmalloc_addr(e))
+-      vfree(e);
+- else
+-      kfree(e);
++ kvfree(e);
+
+// ----------------------------------------------------------------------------
+
+@s_context depends on !patch && (context || org || report)@
+expression e;
+position r.p;
+position j0;
+@@
+
+* if@p (is_vmalloc_addr@j0(e))
+      vfree(e);
+  else
+      kfree(e);
+
+// ----------------------------------------------------------------------------
+
+@script:python s_org depends on org@
+j0 << s_context.j0;
+@@
+
+msg = "Use kvfree."
+coccilib.org.print_todo(j0[0], msg)
+
+// ----------------------------------------------------------------------------
+
+@script:python s_report depends on report@
+j0 << s_context.j0;
+@@
+
+msg = "Use kvfree."
+coccilib.report.print_report(j0[0], msg)

_______________________________________________
Cocci mailing list
[email protected]
https://systeme.lip6.fr/mailman/listinfo/cocci

Reply via email to