c1473dec6556669f1c415a8319ffbe9a1d30e73a
[dragonfly.git] / test / cocci / unlock_return.cocci
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 @@
19 crit_enter();
20 ... when != crit_exit()
21     when any
22     when strict
23 (
24 if (...) { ... when != crit_exit()
25 +   crit_exit();
26     return ...;
27 }
28 |
29 crit_exit();
30 )
31
32 // get_mplock() / rel_mplock()
33 //
34 @@
35 @@
36 get_mplock();
37 ... when != rel_mplock()
38     when any
39     when strict
40 (
41 if (...) { ... when != rel_mplock()
42 +   rel_mplock();
43     return ...;
44 }
45 |
46 rel_mplock();
47 )
48
49 // lockmgr(..., {LK_EXCLUSIVE,LK_SHARED}) / lockmgr(..., LK_RELEASE)
50 //
51 @@
52 expression l;
53 @@
54 lockmgr(l,\(LK_SHARED\|LK_EXCLUSIVE\));
55 ... when != lockmgr(l,LK_RELEASE)
56     when any
57     when strict
58 (
59 if (...) { ... when != lockmgr(l,LK_RELEASE)
60 +   lockmgr(l,LK_RELEASE);
61     return ...;
62 }
63 |
64 lockmgr(l,LK_RELEASE);
65 )
66
67 // lwkt_gettoken(...) / lwkt_reltoken(...)
68 //
69 @@
70 expression l;
71 @@
72 lwkt_gettoken(l);
73 ... when != lwkt_reltoken(l)
74     when any
75     when strict
76 (
77 if (...) { ... when != lwkt_reltoken(l)
78 +   lwkt_reltoken(l);
79     return ...;
80 }
81 |
82 lwkt_reltoken(l);
83 )
84
85 // lwkt_serialize_enter(...) / lwkt_serialize_exit(...)
86 //
87 @@
88 expression l;
89 @@
90 lwkt_serialize_enter(l);
91 ... when != lwkt_serialize_exit(l)
92     when any
93     when strict
94 (
95 if (...) { ... when != lwkt_serialize_exit(l)
96 +   lwkt_serialize_exit(l);
97     return ...;
98 }
99 |
100 lwkt_serialize_exit(l);
101 )
102
103 // spin_lock(...) / spin_unlock(...)
104 //
105 @@
106 expression l;
107 @@
108 spin_lock(l);
109 ... when != spin_unlock(l)
110     when any
111     when strict
112 (
113 if (...) { ... when != spin_unlock(l)
114 +   spin_unlock(l);
115     return ...;
116 }
117 |
118 spin_unlock(l);
119 )