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