[PATCH] coccinelle: api: suggest use of kvfree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

Signed-off-by: Julia Lawall <Julia.Lawall@xxxxxxx>

---
 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)

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Development]     [Kernel Announce]     [Kernel Newbies]     [Linux Networking Development]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Device Mapper]

  Powered by Linux