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