public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] scripts/coccinelle/free: add conditional kfree test
@ 2014-06-17 19:43 Fabian Frederick
  2014-06-17 20:05 ` Joe Perches
  0 siblings, 1 reply; 8+ messages in thread
From: Fabian Frederick @ 2014-06-17 19:43 UTC (permalink / raw)
  To: linux-kernel; +Cc: Fabian Frederick, Julia Lawall, Gilles Muller, Joe Perches

This patch adds a trivial script warning on

if(foo)
	kfree(foo)

(based on checkpatch)

Cc: Julia Lawall <Julia.Lawall@lip6.fr>
Cc: Gilles Muller <Gilles.Muller@lip6.fr>
Cc: Joe Perches <joe@perches.com>
Signed-off-by: Fabian Frederick <fabf@skynet.be>
---
 scripts/coccinelle/free/cond_kfree.cocci | 34 ++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
 create mode 100644 scripts/coccinelle/free/cond_kfree.cocci

diff --git a/scripts/coccinelle/free/cond_kfree.cocci b/scripts/coccinelle/free/cond_kfree.cocci
new file mode 100644
index 0000000..0b8093e
--- /dev/null
+++ b/scripts/coccinelle/free/cond_kfree.cocci
@@ -0,0 +1,34 @@
+/// conditional kfree - NULL check before kfree is not needed.
+///
+/// Based on checkpatch warning
+/// "kfree(NULL) is safe this check is probably not required"
+/// and kfreeaddr.cocci by Julia Lawall.
+///
+/// Comments: -
+/// Options: --no-includes --include-headers
+
+virtual org
+virtual report
+virtual context
+
+@r depends on context || report || org @
+expression E;
+position p;
+@@
+
+* if (E)
+*	kfree@p(E);
+
+@script:python depends on org@
+p << r.p;
+@@
+
+cocci.print_main("kfree", p)
+
+@script:python depends on report@
+p << r.p;
+@@
+
+msg = "WARNING: checking value to avoid kfree(NULL) is unnecessary."
+coccilib.report.print_report(p[0], msg)
+
-- 
1.8.4.5


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-06-18  9:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-06-17 19:43 [PATCH 1/1] scripts/coccinelle/free: add conditional kfree test Fabian Frederick
2014-06-17 20:05 ` Joe Perches
2014-06-17 20:45   ` SF Markus Elfring
2014-06-17 21:33   ` Julia Lawall
2014-06-17 21:58     ` Joe Perches
2014-06-18  5:25       ` Julia Lawall
2014-06-18  5:45         ` Joe Perches
2014-06-18  9:02           ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox