blob: 669b24436248d33a5fde8694375c8528de752f08 [file] [log] [blame]
Nicolas Palixe1050072010-08-24 17:38:58 +02001/// Find functions that refer to GFP_KERNEL but are called with locks held.
Julia Lawall29a36d42012-01-14 23:41:54 +01002//# 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
4//# function under the lock in the first place.
Nicolas Palixe1050072010-08-24 17:38:58 +02005///
6// Confidence: Moderate
Julia Lawall29a36d42012-01-14 23:41:54 +01007// Copyright: (C) 2012 Nicolas Palix. GPLv2.
8// Copyright: (C) 2012 Julia Lawall, INRIA/LIP6. GPLv2.
9// Copyright: (C) 2012 Gilles Muller, INRIA/LiP6. GPLv2.
Nicolas Palixe1050072010-08-24 17:38:58 +020010// URL: http://coccinelle.lip6.fr/
11// Comments:
Nicolas Palix93f14462013-06-20 13:10:56 +020012// Options: --no-includes --include-headers
Nicolas Palixe1050072010-08-24 17:38:58 +020013
14virtual patch
Julia Lawall29a36d42012-01-14 23:41:54 +010015virtual context
16virtual org
17virtual report
Nicolas Palixe1050072010-08-24 17:38:58 +020018
19@gfp exists@
20identifier fn;
21position p;
22@@
23
24fn(...) {
25 ... when != read_unlock_irq(...)
26 when != write_unlock_irq(...)
27 when != read_unlock_irqrestore(...)
28 when != write_unlock_irqrestore(...)
29 when != spin_unlock(...)
30 when != spin_unlock_irq(...)
31 when != spin_unlock_irqrestore(...)
32 when != local_irq_enable(...)
33 when any
34 GFP_KERNEL@p
35 ... when any
36}
37
Julia Lawall29a36d42012-01-14 23:41:54 +010038@locked exists@
Nicolas Palixe1050072010-08-24 17:38:58 +020039identifier gfp.fn;
Julia Lawall29a36d42012-01-14 23:41:54 +010040position p1,p2;
Nicolas Palixe1050072010-08-24 17:38:58 +020041@@
42
43(
Julia Lawall29a36d42012-01-14 23:41:54 +010044read_lock_irq@p1
Nicolas Palixe1050072010-08-24 17:38:58 +020045|
Julia Lawall29a36d42012-01-14 23:41:54 +010046write_lock_irq@p1
Nicolas Palixe1050072010-08-24 17:38:58 +020047|
Julia Lawall29a36d42012-01-14 23:41:54 +010048read_lock_irqsave@p1
Nicolas Palixe1050072010-08-24 17:38:58 +020049|
Julia Lawall29a36d42012-01-14 23:41:54 +010050write_lock_irqsave@p1
Nicolas Palixe1050072010-08-24 17:38:58 +020051|
Julia Lawall29a36d42012-01-14 23:41:54 +010052spin_lock@p1
Nicolas Palixe1050072010-08-24 17:38:58 +020053|
Julia Lawall29a36d42012-01-14 23:41:54 +010054spin_trylock@p1
Nicolas Palixe1050072010-08-24 17:38:58 +020055|
Julia Lawall29a36d42012-01-14 23:41:54 +010056spin_lock_irq@p1
Nicolas Palixe1050072010-08-24 17:38:58 +020057|
Julia Lawall29a36d42012-01-14 23:41:54 +010058spin_lock_irqsave@p1
Nicolas Palixe1050072010-08-24 17:38:58 +020059|
Julia Lawall29a36d42012-01-14 23:41:54 +010060local_irq_disable@p1
Nicolas Palixe1050072010-08-24 17:38:58 +020061)
62 (...)
63... when != read_unlock_irq(...)
64 when != write_unlock_irq(...)
65 when != read_unlock_irqrestore(...)
66 when != write_unlock_irqrestore(...)
67 when != spin_unlock(...)
68 when != spin_unlock_irq(...)
69 when != spin_unlock_irqrestore(...)
70 when != local_irq_enable(...)
Julia Lawall29a36d42012-01-14 23:41:54 +010071fn@p2(...)
Nicolas Palixe1050072010-08-24 17:38:58 +020072
Julia Lawall29a36d42012-01-14 23:41:54 +010073@depends on locked && patch@
Nicolas Palixe1050072010-08-24 17:38:58 +020074position gfp.p;
75@@
76
77- GFP_KERNEL@p
78+ GFP_ATOMIC
Julia Lawall29a36d42012-01-14 23:41:54 +010079
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)