aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/coccinelle/locks/call_kern.cocci
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/coccinelle/locks/call_kern.cocci')
-rw-r--r--scripts/coccinelle/locks/call_kern.cocci67
1 files changed, 49 insertions, 18 deletions
diff --git a/scripts/coccinelle/locks/call_kern.cocci b/scripts/coccinelle/locks/call_kern.cocci
index 00af5344a68f..8f10b49603c3 100644
--- a/scripts/coccinelle/locks/call_kern.cocci
+++ b/scripts/coccinelle/locks/call_kern.cocci
@@ -1,17 +1,20 @@
1/// Find functions that refer to GFP_KERNEL but are called with locks held. 1/// Find functions that refer to GFP_KERNEL but are called with locks held.
2/// The proposed change of converting the GFP_KERNEL is not necessarily the 2//# The proposed change of converting the GFP_KERNEL is not necessarily the
3/// correct one. It may be desired to unlock the lock, or to not call the 3//# correct one. It may be desired to unlock the lock, or to not call the
4/// function under the lock in the first place. 4//# function under the lock in the first place.
5/// 5///
6// Confidence: Moderate 6// Confidence: Moderate
7// Copyright: (C) 2010 Nicolas Palix, DIKU. GPLv2. 7// Copyright: (C) 2012 Nicolas Palix. GPLv2.
8// Copyright: (C) 2010 Julia Lawall, DIKU. GPLv2. 8// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
9// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6. GPLv2. 9// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
10// URL: http://coccinelle.lip6.fr/ 10// URL: http://coccinelle.lip6.fr/
11// Comments: 11// Comments:
12// Options: -no_includes -include_headers 12// Options: -no_includes -include_headers
13 13
14virtual patch 14virtual patch
15virtual context
16virtual org
17virtual report
15 18
16@gfp exists@ 19@gfp exists@
17identifier fn; 20identifier fn;
@@ -32,28 +35,29 @@ fn(...) {
32 ... when any 35 ... when any
33} 36}
34 37
35@locked@ 38@locked exists@
36identifier gfp.fn; 39identifier gfp.fn;
40position p1,p2;
37@@ 41@@
38 42
39( 43(
40read_lock_irq 44read_lock_irq@p1
41| 45|
42write_lock_irq 46write_lock_irq@p1
43| 47|
44read_lock_irqsave 48read_lock_irqsave@p1
45| 49|
46write_lock_irqsave 50write_lock_irqsave@p1
47| 51|
48spin_lock 52spin_lock@p1
49| 53|
50spin_trylock 54spin_trylock@p1
51| 55|
52spin_lock_irq 56spin_lock_irq@p1
53| 57|
54spin_lock_irqsave 58spin_lock_irqsave@p1
55| 59|
56local_irq_disable 60local_irq_disable@p1
57) 61)
58 (...) 62 (...)
59... when != read_unlock_irq(...) 63... when != read_unlock_irq(...)
@@ -64,11 +68,38 @@ local_irq_disable
64 when != spin_unlock_irq(...) 68 when != spin_unlock_irq(...)
65 when != spin_unlock_irqrestore(...) 69 when != spin_unlock_irqrestore(...)
66 when != local_irq_enable(...) 70 when != local_irq_enable(...)
67fn(...) 71fn@p2(...)
68 72
69@depends on locked@ 73@depends on locked && patch@
70position gfp.p; 74position gfp.p;
71@@ 75@@
72 76
73- GFP_KERNEL@p 77- GFP_KERNEL@p
74+ GFP_ATOMIC 78+ GFP_ATOMIC
79
80@depends on locked && !patch@
81position gfp.p;
82@@
83
84* GFP_KERNEL@p
85
86@script:python depends on !patch && org@
87p << gfp.p;
88fn << gfp.fn;
89p1 << locked.p1;
90p2 << locked.p2;
91@@
92
93cocci.print_main("lock",p1)
94cocci.print_secs("call",p2)
95cocci.print_secs("GFP_KERNEL",p)
96
97@script:python depends on !patch && report@
98p << gfp.p;
99fn << gfp.fn;
100p1 << locked.p1;
101p2 << locked.p2;
102@@
103
104msg = "ERROR: function %s called on line %s inside lock on line %s but uses GFP_KERNEL" % (fn,p2[0].line,p1[0].line)
105coccilib.report.print_report(p[0], msg)