aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorFabian Frederick <fabf@skynet.be>2014-08-08 17:23:29 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2014-08-08 18:57:26 -0400
commit791dfeb49519f18a6efea4619f5678457f1532ff (patch)
treed3f6d2e6e526eb6f6d382f5c9980abd8b002ea2c /scripts
parent56106da7932074804f9ef70191f126ea15dc3fc4 (diff)
scripts/coccinelle/free: add NULL test before freeing functions
Warns or generates patch for NULL check before the following functions: kfree usb_free_urb debugfs_remove debugfs_remove_recursive Signed-off-by: Fabian Frederick <fabf@skynet.be> Acked-by: Julia Lawall <Julia.Lawall@lip6.fr> Cc: Gilles Muller <Gilles.Muller@lip6.fr> Cc: Joe Perches <joe@perches.com> Cc: Markus Elfring <elfring@users.sourceforge.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/coccinelle/free/ifnullfree.cocci52
1 files changed, 52 insertions, 0 deletions
diff --git a/scripts/coccinelle/free/ifnullfree.cocci b/scripts/coccinelle/free/ifnullfree.cocci
new file mode 100644
index 000000000000..77ab43f30b8d
--- /dev/null
+++ b/scripts/coccinelle/free/ifnullfree.cocci
@@ -0,0 +1,52 @@
1/// NULL check before some freeing functions is not needed.
2///
3/// Based on checkpatch warning
4/// "kfree(NULL) is safe this check is probably not required"
5/// and kfreeaddr.cocci by Julia Lawall.
6///
7/// Comments: -
8/// Options: --no-includes --include-headers
9
10virtual patch
11virtual org
12virtual report
13virtual context
14
15@r2 depends on patch@
16expression E;
17@@
18- if (E)
19(
20- kfree(E);
21+ kfree(E);
22|
23- debugfs_remove(E);
24+ debugfs_remove(E);
25|
26- debugfs_remove_recursive(E);
27+ debugfs_remove_recursive(E);
28|
29- usb_free_urb(E);
30+ usb_free_urb(E);
31)
32
33@r depends on context || report || org @
34expression E;
35position p;
36@@
37
38* if (E)
39* \(kfree@p\|debugfs_remove@p\|debugfs_remove_recursive@p\|usb_free_urb\)(E);
40
41@script:python depends on org@
42p << r.p;
43@@
44
45cocci.print_main("NULL check before that freeing function is not needed", p)
46
47@script:python depends on report@
48p << r.p;
49@@
50
51msg = "WARNING: NULL check before freeing functions like kfree, debugfs_remove, debugfs_remove_recursive or usb_free_urb is not needed. Maybe consider reorganizing relevant code to avoid passing NULL values."
52coccilib.report.print_report(p[0], msg)