blob: 19c6ee5b986b2019d128142dbfb6ec0f84505000 [file] [log] [blame]
Nicolas Palix54c05622010-08-24 17:39:00 +02001/// Find missing unlocks. This semantic match considers the specific case
2/// where the unlock is missing from an if branch, and there is a lock
3/// before the if and an unlock after the if. False positives are due to
4/// cases where the if branch represents a case where the function is
5/// supposed to exit with the lock held, or where there is some preceding
6/// function call that releases the lock.
7///
8// Confidence: Moderate
Julia Lawall29a36d42012-01-14 23:41:54 +01009// Copyright: (C) 2010-2012 Nicolas Palix. GPLv2.
10// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6. GPLv2.
11// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6. GPLv2.
Nicolas Palix54c05622010-08-24 17:39:00 +020012// URL: http://coccinelle.lip6.fr/
13// Comments:
Nicolas Palix93f14462013-06-20 13:10:56 +020014// Options: --no-includes --include-headers
Nicolas Palix54c05622010-08-24 17:39:00 +020015
Julia Lawall29a36d42012-01-14 23:41:54 +010016virtual context
Nicolas Palix54c05622010-08-24 17:39:00 +020017virtual org
18virtual report
19
20@prelocked@
21position p1,p;
22expression E1;
23@@
24
25(
26mutex_lock@p1
27|
28mutex_trylock@p1
29|
30spin_lock@p1
31|
32spin_trylock@p1
33|
34read_lock@p1
35|
36read_trylock@p1
37|
38write_lock@p1
39|
40write_trylock@p1
41|
42read_lock_irq@p1
43|
44write_lock_irq@p1
45|
46read_lock_irqsave@p1
47|
48write_lock_irqsave@p1
49|
50spin_lock_irq@p1
51|
52spin_lock_irqsave@p1
53) (E1@p,...);
54
55@looped@
56position r;
57@@
58
59for(...;...;...) { <+... return@r ...; ...+> }
60
Julia Lawall29a36d42012-01-14 23:41:54 +010061@err exists@
Nicolas Palix54c05622010-08-24 17:39:00 +020062expression E1;
63position prelocked.p;
64position up != prelocked.p1;
65position r!=looped.r;
66identifier lock,unlock;
67@@
68
Julia Lawall29a36d42012-01-14 23:41:54 +010069*lock(E1@p,...);
Julia Lawall32d05722018-05-21 08:58:48 +020070... when != E1
71 when any
Nicolas Palix54c05622010-08-24 17:39:00 +020072if (...) {
73 ... when != E1
Julia Lawall29a36d42012-01-14 23:41:54 +010074* return@r ...;
Nicolas Palix54c05622010-08-24 17:39:00 +020075}
Julia Lawall32d05722018-05-21 08:58:48 +020076... when != E1
77 when any
Julia Lawall29a36d42012-01-14 23:41:54 +010078*unlock@up(E1,...);
Nicolas Palix54c05622010-08-24 17:39:00 +020079
80@script:python depends on org@
81p << prelocked.p1;
82lock << err.lock;
83unlock << err.unlock;
84p2 << err.r;
85@@
86
87cocci.print_main(lock,p)
88cocci.print_secs(unlock,p2)
89
90@script:python depends on report@
91p << prelocked.p1;
92lock << err.lock;
93unlock << err.unlock;
94p2 << err.r;
95@@
96
97msg = "preceding lock on line %s" % (p[0].line)
98coccilib.report.print_report(p2[0],msg)