diff options
author | Yann Droneaud <ydroneaud@opteya.com> | 2016-05-23 11:07:19 -0400 |
---|---|---|
committer | Michal Marek <mmarek@suse.com> | 2016-06-21 05:43:32 -0400 |
commit | 6dd9379e8f327e70d182b15be3ba21aa2b5d2cba (patch) | |
tree | 0e8d95f8e1748444490f8be79ba1b2dd7bde6553 | |
parent | 7a2358b3818691521c7df531415d1ea4d0398520 (diff) |
coccinelle: also catch kzfree() issues
Since commit 3ef0e5ba4673 ('slab: introduce kzfree()'),
kfree() is no more the only function to be considered:
kzfree() should be recognized too.
In particular, kzfree() must not be called on memory
allocated through devm_*() functions.
Cc: Johannes Weiner <hannes@cmpxchg.org>
Acked-by: Julia Lawall <julia.lawall@lip6.fr>
Signed-off-by: Yann Droneaud <ydroneaud@opteya.com>
Signed-off-by: Michal Marek <mmarek@suse.com>
-rw-r--r-- | scripts/coccinelle/free/devm_free.cocci | 2 | ||||
-rw-r--r-- | scripts/coccinelle/free/ifnullfree.cocci | 4 | ||||
-rw-r--r-- | scripts/coccinelle/free/kfree.cocci | 18 | ||||
-rw-r--r-- | scripts/coccinelle/free/kfreeaddr.cocci | 6 |
4 files changed, 25 insertions, 5 deletions
diff --git a/scripts/coccinelle/free/devm_free.cocci b/scripts/coccinelle/free/devm_free.cocci index 3d9349012bb3..83c03adec1c5 100644 --- a/scripts/coccinelle/free/devm_free.cocci +++ b/scripts/coccinelle/free/devm_free.cocci | |||
@@ -48,6 +48,8 @@ position p; | |||
48 | ( | 48 | ( |
49 | * kfree@p(x) | 49 | * kfree@p(x) |
50 | | | 50 | | |
51 | * kzfree@p(x) | ||
52 | | | ||
51 | * free_irq@p(x) | 53 | * free_irq@p(x) |
52 | | | 54 | | |
53 | * iounmap@p(x) | 55 | * iounmap@p(x) |
diff --git a/scripts/coccinelle/free/ifnullfree.cocci b/scripts/coccinelle/free/ifnullfree.cocci index 52bd235286fa..14a4cd98e83b 100644 --- a/scripts/coccinelle/free/ifnullfree.cocci +++ b/scripts/coccinelle/free/ifnullfree.cocci | |||
@@ -20,6 +20,8 @@ expression E; | |||
20 | ( | 20 | ( |
21 | kfree(E); | 21 | kfree(E); |
22 | | | 22 | | |
23 | kzfree(E); | ||
24 | | | ||
23 | debugfs_remove(E); | 25 | debugfs_remove(E); |
24 | | | 26 | | |
25 | debugfs_remove_recursive(E); | 27 | debugfs_remove_recursive(E); |
@@ -39,7 +41,7 @@ position p; | |||
39 | @@ | 41 | @@ |
40 | 42 | ||
41 | * if (E != NULL) | 43 | * if (E != NULL) |
42 | * \(kfree@p\|debugfs_remove@p\|debugfs_remove_recursive@p\| | 44 | * \(kfree@p\|kzfree@p\|debugfs_remove@p\|debugfs_remove_recursive@p\| |
43 | * usb_free_urb@p\|kmem_cache_destroy@p\|mempool_destroy@p\| | 45 | * usb_free_urb@p\|kmem_cache_destroy@p\|mempool_destroy@p\| |
44 | * dma_pool_destroy@p\)(E); | 46 | * dma_pool_destroy@p\)(E); |
45 | 47 | ||
diff --git a/scripts/coccinelle/free/kfree.cocci b/scripts/coccinelle/free/kfree.cocci index 577b78056990..ac438da4fd7b 100644 --- a/scripts/coccinelle/free/kfree.cocci +++ b/scripts/coccinelle/free/kfree.cocci | |||
@@ -20,7 +20,11 @@ expression E; | |||
20 | position p1; | 20 | position p1; |
21 | @@ | 21 | @@ |
22 | 22 | ||
23 | kfree@p1(E) | 23 | ( |
24 | * kfree@p1(E) | ||
25 | | | ||
26 | * kzfree@p1(E) | ||
27 | ) | ||
24 | 28 | ||
25 | @print expression@ | 29 | @print expression@ |
26 | constant char [] c; | 30 | constant char [] c; |
@@ -60,7 +64,11 @@ position ok; | |||
60 | @@ | 64 | @@ |
61 | 65 | ||
62 | while (1) { ... | 66 | while (1) { ... |
63 | kfree@ok(E) | 67 | ( |
68 | * kfree@ok(E) | ||
69 | | | ||
70 | * kzfree@ok(E) | ||
71 | ) | ||
64 | ... when != break; | 72 | ... when != break; |
65 | when != goto l; | 73 | when != goto l; |
66 | when forall | 74 | when forall |
@@ -74,7 +82,11 @@ statement S; | |||
74 | position free.p1!=loop.ok,p2!={print.p,sz.p}; | 82 | position free.p1!=loop.ok,p2!={print.p,sz.p}; |
75 | @@ | 83 | @@ |
76 | 84 | ||
77 | kfree@p1(E,...) | 85 | ( |
86 | * kfree@p1(E,...) | ||
87 | | | ||
88 | * kzfree@p1(E,...) | ||
89 | ) | ||
78 | ... | 90 | ... |
79 | ( | 91 | ( |
80 | iter(...,subE,...) S // no use | 92 | iter(...,subE,...) S // no use |
diff --git a/scripts/coccinelle/free/kfreeaddr.cocci b/scripts/coccinelle/free/kfreeaddr.cocci index ce8aacc314cb..d46063b1db8b 100644 --- a/scripts/coccinelle/free/kfreeaddr.cocci +++ b/scripts/coccinelle/free/kfreeaddr.cocci | |||
@@ -16,7 +16,11 @@ identifier f; | |||
16 | position p; | 16 | position p; |
17 | @@ | 17 | @@ |
18 | 18 | ||
19 | ( | ||
19 | * kfree@p(&e->f) | 20 | * kfree@p(&e->f) |
21 | | | ||
22 | * kzfree@p(&e->f) | ||
23 | ) | ||
20 | 24 | ||
21 | @script:python depends on org@ | 25 | @script:python depends on org@ |
22 | p << r.p; | 26 | p << r.p; |
@@ -28,5 +32,5 @@ cocci.print_main("kfree",p) | |||
28 | p << r.p; | 32 | p << r.p; |
29 | @@ | 33 | @@ |
30 | 34 | ||
31 | msg = "ERROR: kfree of structure field" | 35 | msg = "ERROR: invalid free of structure field" |
32 | coccilib.report.print_report(p[0],msg) | 36 | coccilib.report.print_report(p[0],msg) |