Add a coccinelle patch to find missing lock release before return.
[dragonfly.git] / test / cocci / unlock_return.cocci
CommitLineData
49357869
SW
1//
2// Look for missing lock releases before returning from a function.
3//
4// NOTES
5// -----
6// * The results of running this patch have to be carefully reviewed.
7// Some functions legally return with the lock held, even if the
8// below pattern matches. Some other functions begin with the lock
9// held, only to release and then reaquire it again.
10//
11// * Consider using -timeout because it might run a long time
12// (indefinitely?) on some files.
13//
14
15// crit_enter() / crit_exit()
16//
17@@
18@@
19crit_enter();
20... when != crit_exit()
21 when any
22 when strict
23(
24if (...) { ... when != crit_exit()
25+ crit_exit();
26 return ...;
27}
28|
29crit_exit();
30)
31
32// get_mplock() / rel_mplock()
33//
34@@
35@@
36get_mplock();
37... when != rel_mplock()
38 when any
39 when strict
40(
41if (...) { ... when != rel_mplock()
42+ rel_mplock();
43 return ...;
44}
45|
46rel_mplock();
47)
48
49// lockmgr(..., {LK_EXCLUSIVE,LK_SHARED}) / lockmgr(..., LK_RELEASE)
50//
51@@
52expression l;
53@@
54lockmgr(l,\(LK_SHARED\|LK_EXCLUSIVE\));
55... when != lockmgr(l,LK_RELEASE)
56 when any
57 when strict
58(
59if (...) { ... when != lockmgr(l,LK_RELEASE)
60+ lockmgr(l,LK_RELEASE);
61 return ...;
62}
63|
64lockmgr(l,LK_RELEASE);
65)
66
67// lwkt_gettoken(...) / lwkt_reltoken(...)
68//
69@@
70expression l;
71@@
72lwkt_gettoken(l);
73... when != lwkt_reltoken(l)
74 when any
75 when strict
76(
77if (...) { ... when != lwkt_reltoken(l)
78+ lwkt_reltoken(l);
79 return ...;
80}
81|
82lwkt_reltoken(l);
83)
84
85// lwkt_serialize_enter(...) / lwkt_serialize_exit(...)
86//
87@@
88expression l;
89@@
90lwkt_serialize_enter(l);
91... when != lwkt_serialize_exit(l)
92 when any
93 when strict
94(
95if (...) { ... when != lwkt_serialize_exit(l)
96+ lwkt_serialize_exit(l);
97 return ...;
98}
99|
100lwkt_serialize_exit(l);
101)
102
103// spin_lock(...) / spin_unlock(...)
104//
105@@
106expression l;
107@@
108spin_lock(l);
109... when != spin_unlock(l)
110 when any
111 when strict
112(
113if (...) { ... when != spin_unlock(l)
114+ spin_unlock(l);
115 return ...;
116}
117|
118spin_unlock(l);
119)