2 * Copyright (C) 2009 Dan Carpenter.
3 * Copyright (C) 2019 Oracle.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
22 #include "smatch_extra.h"
23 #include "smatch_slist.h"
49 const char *get_lock_name(enum lock_type type
)
51 static const char *names
[] = {
52 [spin_lock
] = "spin_lock",
53 [read_lock
] = "read_lock",
54 [write_lock
] = "write_lock",
56 [bottom_half
] = "bottom_half",
59 [prepare_lock
] = "prepare_lock",
60 [enable_lock
] = "enable_lock",
62 [rcu_read
] = "rcu_read",
77 const sval_t
*implies_start
, *implies_end
;
81 static struct lock_info lock_table
[] = {
82 {"spin_lock", LOCK
, spin_lock
, 0, "$"},
83 {"spin_unlock", UNLOCK
, spin_lock
, 0, "$"},
84 {"spin_lock_nested", LOCK
, spin_lock
, 0, "$"},
85 {"_spin_lock", LOCK
, spin_lock
, 0, "$"},
86 {"_spin_unlock", UNLOCK
, spin_lock
, 0, "$"},
87 {"_spin_lock_nested", LOCK
, spin_lock
, 0, "$"},
88 {"__spin_lock", LOCK
, spin_lock
, 0, "$"},
89 {"__spin_unlock", UNLOCK
, spin_lock
, 0, "$"},
90 {"__spin_lock_nested", LOCK
, spin_lock
, 0, "$"},
91 {"raw_spin_lock", LOCK
, spin_lock
, 0, "$"},
92 {"raw_spin_unlock", UNLOCK
, spin_lock
, 0, "$"},
93 {"_raw_spin_lock", LOCK
, spin_lock
, 0, "$"},
94 {"_raw_spin_lock_nested", LOCK
, spin_lock
, 0, "$"},
95 {"_raw_spin_unlock", UNLOCK
, spin_lock
, 0, "$"},
96 {"__raw_spin_lock", LOCK
, spin_lock
, 0, "$"},
97 {"__raw_spin_unlock", UNLOCK
, spin_lock
, 0, "$"},
99 {"spin_lock_irq", LOCK
, spin_lock
, 0, "$"},
100 {"spin_unlock_irq", UNLOCK
, spin_lock
, 0, "$"},
101 {"_spin_lock_irq", LOCK
, spin_lock
, 0, "$"},
102 {"_spin_unlock_irq", UNLOCK
, spin_lock
, 0, "$"},
103 {"__spin_lock_irq", LOCK
, spin_lock
, 0, "$"},
104 {"__spin_unlock_irq", UNLOCK
, spin_lock
, 0, "$"},
105 {"_raw_spin_lock_irq", LOCK
, spin_lock
, 0, "$"},
106 {"_raw_spin_unlock_irq", UNLOCK
, spin_lock
, 0, "$"},
107 {"__raw_spin_unlock_irq", UNLOCK
, spin_lock
, 0, "$"},
108 {"spin_lock_irqsave", LOCK
, spin_lock
, 0, "$"},
109 {"spin_unlock_irqrestore", UNLOCK
, spin_lock
, 0, "$"},
110 {"_spin_lock_irqsave", LOCK
, spin_lock
, 0, "$"},
111 {"_spin_unlock_irqrestore", UNLOCK
, spin_lock
, 0, "$"},
112 {"__spin_lock_irqsave", LOCK
, spin_lock
, 0, "$"},
113 {"__spin_unlock_irqrestore", UNLOCK
, spin_lock
, 0, "$"},
114 {"_raw_spin_lock_irqsave", LOCK
, spin_lock
, 0, "$"},
115 {"_raw_spin_unlock_irqrestore", UNLOCK
, spin_lock
, 0, "$"},
116 {"__raw_spin_lock_irqsave", LOCK
, spin_lock
, 0, "$"},
117 {"__raw_spin_unlock_irqrestore", UNLOCK
, spin_lock
, 0, "$"},
118 {"spin_lock_irqsave_nested", LOCK
, spin_lock
, 0, "$"},
119 {"_spin_lock_irqsave_nested", LOCK
, spin_lock
, 0, "$"},
120 {"__spin_lock_irqsave_nested", LOCK
, spin_lock
, 0, "$"},
121 {"_raw_spin_lock_irqsave_nested", LOCK
, spin_lock
, 0, "$"},
122 {"spin_lock_bh", LOCK
, spin_lock
, 0, "$"},
123 {"spin_unlock_bh", UNLOCK
, spin_lock
, 0, "$"},
124 {"_spin_lock_bh", LOCK
, spin_lock
, 0, "$"},
125 {"_spin_unlock_bh", UNLOCK
, spin_lock
, 0, "$"},
126 {"__spin_lock_bh", LOCK
, spin_lock
, 0, "$"},
127 {"__spin_unlock_bh", UNLOCK
, spin_lock
, 0, "$"},
129 {"spin_trylock", LOCK
, spin_lock
, 0, "$", &int_one
, &int_one
},
130 {"_spin_trylock", LOCK
, spin_lock
, 0, "$", &int_one
, &int_one
},
131 {"__spin_trylock", LOCK
, spin_lock
, 0, "$", &int_one
, &int_one
},
132 {"raw_spin_trylock", LOCK
, spin_lock
, 0, "$", &int_one
, &int_one
},
133 {"_raw_spin_trylock", LOCK
, spin_lock
, 0, "$", &int_one
, &int_one
},
134 {"spin_trylock_irq", LOCK
, spin_lock
, 0, "$", &int_one
, &int_one
},
135 {"spin_trylock_irqsave", LOCK
, spin_lock
, 0, "$", &int_one
, &int_one
},
136 {"spin_trylock_bh", LOCK
, spin_lock
, 0, "$", &int_one
, &int_one
},
137 {"_spin_trylock_bh", LOCK
, spin_lock
, 0, "$", &int_one
, &int_one
},
138 {"__spin_trylock_bh", LOCK
, spin_lock
, 0, "$", &int_one
, &int_one
},
139 {"__raw_spin_trylock", LOCK
, spin_lock
, 0, "$", &int_one
, &int_one
},
140 {"_atomic_dec_and_lock", LOCK
, spin_lock
, 1, "$", &int_one
, &int_one
},
142 {"read_lock", LOCK
, read_lock
, 0, "$"},
143 {"down_read", LOCK
, read_lock
, 0, "$"},
144 {"down_read_nested", LOCK
, read_lock
, 0, "$"},
145 {"down_read_trylock", LOCK
, read_lock
, 0, "$", &int_one
, &int_one
},
146 {"down_read_killable", LOCK
, read_lock
, 0, "$", &int_zero
, &int_zero
},
147 {"up_read", UNLOCK
, read_lock
, 0, "$"},
148 {"read_unlock", UNLOCK
, read_lock
, 0, "$"},
149 {"_read_lock", LOCK
, read_lock
, 0, "$"},
150 {"_read_unlock", UNLOCK
, read_lock
, 0, "$"},
151 {"__read_lock", LOCK
, read_lock
, 0, "$"},
152 {"__read_unlock", UNLOCK
, read_lock
, 0, "$"},
153 {"_raw_read_lock", LOCK
, read_lock
, 0, "$"},
154 {"_raw_read_unlock", UNLOCK
, read_lock
, 0, "$"},
155 {"__raw_read_lock", LOCK
, read_lock
, 0, "$"},
156 {"__raw_read_unlock", UNLOCK
, read_lock
, 0, "$"},
157 {"read_lock_irq", LOCK
, read_lock
, 0, "$"},
158 {"read_unlock_irq" , UNLOCK
, read_lock
, 0, "$"},
159 {"_read_lock_irq", LOCK
, read_lock
, 0, "$"},
160 {"_read_unlock_irq", UNLOCK
, read_lock
, 0, "$"},
161 {"__read_lock_irq", LOCK
, read_lock
, 0, "$"},
162 {"__read_unlock_irq", UNLOCK
, read_lock
, 0, "$"},
163 {"_raw_read_unlock_irq", UNLOCK
, read_lock
, 0, "$"},
164 {"_raw_read_lock_irq", LOCK
, read_lock
, 0, "$"},
165 {"_raw_read_lock_bh", LOCK
, read_lock
, 0, "$"},
166 {"_raw_read_unlock_bh", UNLOCK
, read_lock
, 0, "$"},
167 {"read_lock_irqsave", LOCK
, read_lock
, 0, "$"},
168 {"read_unlock_irqrestore", UNLOCK
, read_lock
, 0, "$"},
169 {"_read_lock_irqsave", LOCK
, read_lock
, 0, "$"},
170 {"_read_unlock_irqrestore", UNLOCK
, read_lock
, 0, "$"},
171 {"__read_lock_irqsave", LOCK
, read_lock
, 0, "$"},
172 {"__read_unlock_irqrestore", UNLOCK
, read_lock
, 0, "$"},
173 {"read_lock_bh", LOCK
, read_lock
, 0, "$"},
174 {"read_unlock_bh", UNLOCK
, read_lock
, 0, "$"},
175 {"_read_lock_bh", LOCK
, read_lock
, 0, "$"},
176 {"_read_unlock_bh", UNLOCK
, read_lock
, 0, "$"},
177 {"__read_lock_bh", LOCK
, read_lock
, 0, "$"},
178 {"__read_unlock_bh", UNLOCK
, read_lock
, 0, "$"},
179 {"__raw_read_lock_bh", LOCK
, read_lock
, 0, "$"},
180 {"__raw_read_unlock_bh", UNLOCK
, read_lock
, 0, "$"},
182 {"_raw_read_lock_irqsave", LOCK
, read_lock
, 0, "$"},
183 {"_raw_read_lock_irqsave", LOCK
, irq
, RETURN_VAL
, "$"},
184 {"_raw_read_unlock_irqrestore", UNLOCK
, read_lock
, 0, "$"},
185 {"_raw_read_unlock_irqrestore", RESTORE
, irq
, 1, "$"},
186 {"_raw_spin_lock_bh", LOCK
, read_lock
, 0, "$"},
187 {"_raw_spin_lock_bh", LOCK
, bottom_half
, NO_ARG
, "bh"},
188 {"_raw_spin_lock_nest_lock", LOCK
, read_lock
, 0, "$"},
189 {"_raw_spin_unlock_bh", UNLOCK
, read_lock
, 0, "$"},
190 {"_raw_spin_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, "bh"},
191 {"_raw_write_lock_irqsave", LOCK
, write_lock
, 0, "$"},
192 {"_raw_write_lock_irqsave", LOCK
, irq
, RETURN_VAL
, "$"},
193 {"_raw_write_unlock_irqrestore", UNLOCK
, write_lock
, 0, "$"},
194 {"_raw_write_unlock_irqrestore", RESTORE
, irq
, 1, "$"},
195 {"__raw_write_unlock_irq", UNLOCK
, write_lock
, 0, "$"},
196 {"__raw_write_unlock_irq", UNLOCK
, irq
, 0, "irq"},
197 {"__raw_write_unlock_irqrestore", UNLOCK
, write_lock
, 0, "$"},
198 {"__raw_write_unlock_irqrestore", RESTORE
, irq
, 1, "$"},
200 {"generic__raw_read_trylock", LOCK
, read_lock
, 0, "$", &int_one
, &int_one
},
201 {"read_trylock", LOCK
, read_lock
, 0, "$", &int_one
, &int_one
},
202 {"_read_trylock", LOCK
, read_lock
, 0, "$", &int_one
, &int_one
},
203 {"raw_read_trylock", LOCK
, read_lock
, 0, "$", &int_one
, &int_one
},
204 {"_raw_read_trylock", LOCK
, read_lock
, 0, "$", &int_one
, &int_one
},
205 {"__raw_read_trylock", LOCK
, read_lock
, 0, "$", &int_one
, &int_one
},
206 {"__read_trylock", LOCK
, read_lock
, 0, "$", &int_one
, &int_one
},
208 {"write_lock", LOCK
, write_lock
, 0, "$"},
209 {"down_write", LOCK
, write_lock
, 0, "$"},
210 {"down_write_nested", LOCK
, write_lock
, 0, "$"},
211 {"up_write", UNLOCK
, write_lock
, 0, "$"},
212 {"write_unlock", UNLOCK
, write_lock
, 0, "$"},
213 {"_write_lock", LOCK
, write_lock
, 0, "$"},
214 {"_write_unlock", UNLOCK
, write_lock
, 0, "$"},
215 {"__write_lock", LOCK
, write_lock
, 0, "$"},
216 {"__write_unlock", UNLOCK
, write_lock
, 0, "$"},
217 {"write_lock_irq", LOCK
, write_lock
, 0, "$"},
218 {"write_unlock_irq", UNLOCK
, write_lock
, 0, "$"},
219 {"_write_lock_irq", LOCK
, write_lock
, 0, "$"},
220 {"_write_unlock_irq", UNLOCK
, write_lock
, 0, "$"},
221 {"__write_lock_irq", LOCK
, write_lock
, 0, "$"},
222 {"__write_unlock_irq", UNLOCK
, write_lock
, 0, "$"},
223 {"_raw_write_unlock_irq", UNLOCK
, write_lock
, 0, "$"},
224 {"write_lock_irqsave", LOCK
, write_lock
, 0, "$"},
225 {"write_unlock_irqrestore", UNLOCK
, write_lock
, 0, "$"},
226 {"_write_lock_irqsave", LOCK
, write_lock
, 0, "$"},
227 {"_write_unlock_irqrestore", UNLOCK
, write_lock
, 0, "$"},
228 {"__write_lock_irqsave", LOCK
, write_lock
, 0, "$"},
229 {"__write_unlock_irqrestore", UNLOCK
, write_lock
, 0, "$"},
230 {"write_lock_bh", LOCK
, write_lock
, 0, "$"},
231 {"write_unlock_bh", UNLOCK
, write_lock
, 0, "$"},
232 {"_write_lock_bh", LOCK
, write_lock
, 0, "$"},
233 {"_write_unlock_bh", UNLOCK
, write_lock
, 0, "$"},
234 {"__write_lock_bh", LOCK
, write_lock
, 0, "$"},
235 {"__write_unlock_bh", UNLOCK
, write_lock
, 0, "$"},
236 {"_raw_write_lock", LOCK
, write_lock
, 0, "$"},
237 {"__raw_write_lock", LOCK
, write_lock
, 0, "$"},
238 {"_raw_write_unlock", UNLOCK
, write_lock
, 0, "$"},
239 {"__raw_write_unlock", UNLOCK
, write_lock
, 0, "$"},
240 {"_raw_write_lock_bh", LOCK
, write_lock
, 0, "$"},
241 {"_raw_write_unlock_bh", UNLOCK
, write_lock
, 0, "$"},
242 {"_raw_write_lock_irq", LOCK
, write_lock
, 0, "$"},
244 {"write_trylock", LOCK
, write_lock
, 0, "$", &int_one
, &int_one
},
245 {"_write_trylock", LOCK
, write_lock
, 0, "$", &int_one
, &int_one
},
246 {"raw_write_trylock", LOCK
, write_lock
, 0, "$", &int_one
, &int_one
},
247 {"_raw_write_trylock", LOCK
, write_lock
, 0, "$", &int_one
, &int_one
},
248 {"__write_trylock", LOCK
, write_lock
, 0, "$", &int_one
, &int_one
},
249 {"__raw_write_trylock", LOCK
, write_lock
, 0, "$", &int_one
, &int_one
},
250 {"down_write_trylock", LOCK
, write_lock
, 0, "$", &int_one
, &int_one
},
251 {"down_write_killable", LOCK
, write_lock
, 0, "$", &int_zero
, &int_zero
},
253 {"down", LOCK
, sem
, 0, "$"},
254 {"up", UNLOCK
, sem
, 0, "$"},
255 {"down_trylock", LOCK
, sem
, 0, "$", &int_zero
, &int_zero
},
256 {"down_timeout", LOCK
, sem
, 0, "$", &int_zero
, &int_zero
},
257 {"down_interruptible", LOCK
, sem
, 0, "$", &int_zero
, &int_zero
},
258 {"down_killable", LOCK
, sem
, 0, "$", &int_zero
, &int_zero
},
261 {"mutex_lock", LOCK
, mutex
, 0, "$"},
262 {"mutex_unlock", UNLOCK
, mutex
, 0, "$"},
263 {"mutex_destroy", RESTORE
, mutex
, 0, "$"},
264 {"mutex_lock_nested", LOCK
, mutex
, 0, "$"},
265 {"mutex_lock_io", LOCK
, mutex
, 0, "$"},
266 {"mutex_lock_io_nested", LOCK
, mutex
, 0, "$"},
268 {"mutex_lock_interruptible", LOCK
, mutex
, 0, "$", &int_zero
, &int_zero
},
269 {"mutex_lock_interruptible_nested", LOCK
, mutex
, 0, "$", &int_zero
, &int_zero
},
270 {"mutex_lock_killable", LOCK
, mutex
, 0, "$", &int_zero
, &int_zero
},
271 {"mutex_lock_killable_nested", LOCK
, mutex
, 0, "$", &int_zero
, &int_zero
},
273 {"mutex_trylock", LOCK
, mutex
, 0, "$", &int_one
, &int_one
},
275 {"ww_mutex_lock", LOCK
, mutex
, 0, "$"},
276 {"__ww_mutex_lock", LOCK
, mutex
, 0, "$"},
277 {"ww_mutex_lock_interruptible", LOCK
, mutex
, 0, "$", &int_zero
, &int_zero
},
278 {"ww_mutex_unlock", UNLOCK
, mutex
, 0, "$"},
280 {"raw_local_irq_disable", LOCK
, irq
, NO_ARG
, "irq"},
281 {"raw_local_irq_enable", UNLOCK
, irq
, NO_ARG
, "irq"},
282 {"spin_lock_irq", LOCK
, irq
, NO_ARG
, "irq"},
283 {"spin_unlock_irq", UNLOCK
, irq
, NO_ARG
, "irq"},
284 {"_spin_lock_irq", LOCK
, irq
, NO_ARG
, "irq"},
285 {"_spin_unlock_irq", UNLOCK
, irq
, NO_ARG
, "irq"},
286 {"__spin_lock_irq", LOCK
, irq
, NO_ARG
, "irq"},
287 {"__spin_unlock_irq", UNLOCK
, irq
, NO_ARG
, "irq"},
288 {"_raw_spin_lock_irq", LOCK
, irq
, NO_ARG
, "irq"},
289 {"_raw_spin_unlock_irq", UNLOCK
, irq
, NO_ARG
, "irq"},
290 {"__raw_spin_unlock_irq", UNLOCK
, irq
, NO_ARG
, "irq"},
291 {"spin_trylock_irq", LOCK
, irq
, NO_ARG
, "irq", &int_one
, &int_one
},
292 {"read_lock_irq", LOCK
, irq
, NO_ARG
, "irq"},
293 {"read_unlock_irq", UNLOCK
, irq
, NO_ARG
, "irq"},
294 {"_read_lock_irq", LOCK
, irq
, NO_ARG
, "irq"},
295 {"_read_unlock_irq", UNLOCK
, irq
, NO_ARG
, "irq"},
296 {"__read_lock_irq", LOCK
, irq
, NO_ARG
, "irq"},
297 {"_raw_read_lock_irq", LOCK
, irq
, NO_ARG
, "irq"},
298 {"__read_unlock_irq", UNLOCK
, irq
, NO_ARG
, "irq"},
299 {"_raw_read_unlock_irq", UNLOCK
, irq
, NO_ARG
, "irq"},
300 {"write_lock_irq", LOCK
, irq
, NO_ARG
, "irq"},
301 {"write_unlock_irq", UNLOCK
, irq
, NO_ARG
, "irq"},
302 {"_write_lock_irq", LOCK
, irq
, NO_ARG
, "irq"},
303 {"_write_unlock_irq", UNLOCK
, irq
, NO_ARG
, "irq"},
304 {"__write_lock_irq", LOCK
, irq
, NO_ARG
, "irq"},
305 {"__write_unlock_irq", UNLOCK
, irq
, NO_ARG
, "irq"},
306 {"_raw_write_lock_irq", LOCK
, irq
, NO_ARG
, "irq"},
307 {"_raw_write_unlock_irq", UNLOCK
, irq
, NO_ARG
, "irq"},
309 {"arch_local_irq_save", LOCK
, irq
, RETURN_VAL
, "$"},
310 {"arch_local_irq_restore", RESTORE
, irq
, 0, "$"},
311 {"__raw_local_irq_save", LOCK
, irq
, RETURN_VAL
, "$"},
312 {"raw_local_irq_restore", RESTORE
, irq
, 0, "$"},
313 {"spin_lock_irqsave_nested", LOCK
, irq
, RETURN_VAL
, "$"},
314 {"spin_lock_irqsave", LOCK
, irq
, 1, "$"},
315 {"spin_unlock_irqrestore", RESTORE
, irq
, 1, "$"},
316 {"_spin_lock_irqsave_nested", LOCK
, irq
, RETURN_VAL
, "$"},
317 {"_spin_lock_irqsave", LOCK
, irq
, RETURN_VAL
, "$"},
318 {"_spin_lock_irqsave", LOCK
, irq
, 1, "$"},
319 {"_spin_unlock_irqrestore", RESTORE
, irq
, 1, "$"},
320 {"__spin_lock_irqsave_nested", LOCK
, irq
, 1, "$"},
321 {"__spin_lock_irqsave", LOCK
, irq
, 1, "$"},
322 {"__spin_unlock_irqrestore", RESTORE
, irq
, 1, "$"},
323 {"_raw_spin_lock_irqsave", LOCK
, irq
, RETURN_VAL
, "$"},
324 {"_raw_spin_lock_irqsave", LOCK
, irq
, 1, "$"},
325 {"_raw_spin_unlock_irqrestore", RESTORE
, irq
, 1, "$"},
326 {"__raw_spin_lock_irqsave", LOCK
, irq
, RETURN_VAL
, "$"},
327 {"__raw_spin_unlock_irqrestore", RESTORE
, irq
, 1, "$"},
328 {"_raw_spin_lock_irqsave_nested", LOCK
, irq
, RETURN_VAL
, "$"},
329 {"spin_trylock_irqsave", LOCK
, irq
, 1, "$", &int_one
, &int_one
},
330 {"read_lock_irqsave", LOCK
, irq
, RETURN_VAL
, "$"},
331 {"read_lock_irqsave", LOCK
, irq
, 1, "$"},
332 {"read_unlock_irqrestore", RESTORE
, irq
, 1, "$"},
333 {"_read_lock_irqsave", LOCK
, irq
, RETURN_VAL
, "$"},
334 {"_read_lock_irqsave", LOCK
, irq
, 1, "$"},
335 {"_read_unlock_irqrestore", RESTORE
, irq
, 1, "$"},
336 {"__read_lock_irqsave", LOCK
, irq
, RETURN_VAL
, "$"},
337 {"__read_unlock_irqrestore", RESTORE
, irq
, 1, "$"},
338 {"write_lock_irqsave", LOCK
, irq
, RETURN_VAL
, "$"},
339 {"write_lock_irqsave", LOCK
, irq
, 1, "$"},
340 {"write_unlock_irqrestore", RESTORE
, irq
, 1, "$"},
341 {"_write_lock_irqsave", LOCK
, irq
, RETURN_VAL
, "$"},
342 {"_write_lock_irqsave", LOCK
, irq
, 1, "$"},
343 {"_write_unlock_irqrestore", RESTORE
, irq
, 1, "$"},
344 {"__write_lock_irqsave", LOCK
, irq
, RETURN_VAL
, "$"},
345 {"__write_unlock_irqrestore", RESTORE
, irq
, 1, "$"},
347 {"local_bh_disable", LOCK
, bottom_half
, NO_ARG
, "bh"},
348 {"_local_bh_disable", LOCK
, bottom_half
, NO_ARG
, "bh"},
349 {"__local_bh_disable", LOCK
, bottom_half
, NO_ARG
, "bh"},
350 {"local_bh_enable", UNLOCK
, bottom_half
, NO_ARG
, "bh"},
351 {"_local_bh_enable", UNLOCK
, bottom_half
, NO_ARG
, "bh"},
352 {"__local_bh_enable", UNLOCK
, bottom_half
, NO_ARG
, "bh"},
353 {"spin_lock_bh", LOCK
, bottom_half
, NO_ARG
, "bh"},
354 {"spin_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, "bh"},
355 {"_spin_lock_bh", LOCK
, bottom_half
, NO_ARG
, "bh"},
356 {"_spin_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, "bh"},
357 {"__spin_lock_bh", LOCK
, bottom_half
, NO_ARG
, "bh"},
358 {"__spin_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, "bh"},
359 {"read_lock_bh", LOCK
, bottom_half
, NO_ARG
, "bh"},
360 {"read_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, "bh"},
361 {"_read_lock_bh", LOCK
, bottom_half
, NO_ARG
, "bh"},
362 {"_read_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, "bh"},
363 {"__read_lock_bh", LOCK
, bottom_half
, NO_ARG
, "bh"},
364 {"__read_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, "bh"},
365 {"_raw_read_lock_bh", LOCK
, bottom_half
, NO_ARG
, "bh"},
366 {"_raw_read_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, "bh"},
367 {"write_lock_bh", LOCK
, bottom_half
, NO_ARG
, "bh"},
368 {"write_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, "bh"},
369 {"_write_lock_bh", LOCK
, bottom_half
, NO_ARG
, "bh"},
370 {"_write_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, "bh"},
371 {"__write_lock_bh", LOCK
, bottom_half
, NO_ARG
, "bh"},
372 {"__write_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, "bh"},
373 {"_raw_write_lock_bh", LOCK
, bottom_half
, NO_ARG
, "bh"},
374 {"_raw_write_unlock_bh",UNLOCK
, bottom_half
, NO_ARG
, "bh"},
375 {"spin_trylock_bh", LOCK
, bottom_half
, NO_ARG
, "bh", &int_one
, &int_one
},
376 {"_spin_trylock_bh", LOCK
, bottom_half
, NO_ARG
, "bh", &int_one
, &int_one
},
377 {"__spin_trylock_bh", LOCK
, bottom_half
, NO_ARG
, "bh", &int_one
, &int_one
},
379 {"ffs_mutex_lock", LOCK
, mutex
, 0, "$", &int_zero
, &int_zero
},
381 {"clk_prepare_lock", LOCK
, prepare_lock
, NO_ARG
, "clk"},
382 {"clk_prepare_unlock", UNLOCK
, prepare_lock
, NO_ARG
, "clk"},
383 {"clk_enable_lock", LOCK
, enable_lock
, -1, "$"},
384 {"clk_enable_unlock", UNLOCK
, enable_lock
, 0, "$"},
386 {"dma_resv_lock", LOCK
, mutex
, 0, "$", &int_zero
, &int_zero
},
387 {"dma_resv_trylock", LOCK
, mutex
, 0, "$", &int_one
, &int_one
},
388 {"dma_resv_lock_interruptible", LOCK
, mutex
, 0, "$", &int_zero
, &int_zero
},
389 {"dma_resv_unlock", UNLOCK
, mutex
, 0, "$"},
391 {"modeset_lock", LOCK
, mutex
, 0, "$", &int_zero
, &int_zero
},
392 {"drm_ modeset_lock", LOCK
, mutex
, 0, "$", &int_zero
, &int_zero
},
393 {"drm_modeset_lock_single_interruptible", LOCK
, mutex
, 0, "$", &int_zero
, &int_zero
},
394 {"modeset_unlock", UNLOCK
, mutex
, 0, "$"},
395 // {"nvkm_i2c_aux_acquire", LOCK, mutex,
396 // {"i915_gem_object_lock_interruptible", LOCK, mutex,
398 {"reiserfs_write_lock_nested", LOCK
, mutex
, 0, "$"},
399 {"reiserfs_write_unlock_nested", UNLOCK
, mutex
, 0, "$"},
401 {"rw_lock", LOCK
, write_lock
, 1, "$"},
402 {"rw_unlock", UNLOCK
, write_lock
, 1, "$"},
404 {"sem_lock", LOCK
, mutex
, 0, "$"},
405 {"sem_unlock", UNLOCK
, mutex
, 0, "$"},
407 {"rcu_lock_acquire", LOCK
, rcu
, NO_ARG
, "rcu"},
408 {"rcu_lock_release", UNLOCK
, rcu
, NO_ARG
, "rcu"},
410 {"rcu_read_lock", LOCK
, rcu_read
, NO_ARG
, "rcu_read"},
411 {"rcu_read_unlock", UNLOCK
, rcu_read
, NO_ARG
, "rcu_read"},
412 {"rcu_read_lock_bh", LOCK
, rcu_read
, NO_ARG
, "rcu_read"},
413 {"rcu_read_unlock_bh", UNLOCK
, rcu_read
, NO_ARG
, "rcu_read"},
415 {"rcu_read_lock_sched", LOCK
, rcu_read
, NO_ARG
, "rcu_read"},
416 {"rcu_read_lock_sched_notrace", LOCK
, rcu_read
, NO_ARG
, "rcu_read"},
417 {"rcu_read_unlock_sched", UNLOCK
, rcu_read
, NO_ARG
, "rcu_read"},
418 {"rcu_read_unlock_sched_notrace", UNLOCK
, rcu_read
, NO_ARG
, "rcu_read"},
420 {"bch_write_bdev_super", IGNORE_LOCK
, sem
, 0, "&$->sb_write_mutex"},
421 {"dlfb_set_video_mode", IGNORE_LOCK
, sem
, 0, "&$->urbs.limit_sem"},
423 {"efx_rwsem_assert_write_locked", IGNORE_LOCK
, sem
, 0, "&"},
434 static struct macro_info macro_table
[] = {
435 {"genpd_lock", LOCK
, 0},
436 {"genpd_lock_nested", LOCK
, 0},
437 {"genpd_lock_interruptible", LOCK
, 0},
438 {"genpd_unlock", UNLOCK
, 0},
441 static const char *false_positives
[][2] = {
442 {"fs/jffs2/", "->alloc_sem"},
443 {"fs/xfs/", "->b_sema"},
444 {"mm/", "pvmw->ptl"},
447 static struct stree
*start_states
;
449 static struct tracker_list
*locks
;
451 static struct expression
*ignored_reset
;
452 static void reset(struct sm_state
*sm
, struct expression
*mod_expr
)
454 struct expression
*faked
;
456 if (mod_expr
&& mod_expr
->type
== EXPR_ASSIGNMENT
&&
457 mod_expr
->left
== ignored_reset
)
459 faked
= get_faked_expression();
460 if (faked
&& faked
->type
== EXPR_ASSIGNMENT
&&
461 faked
->left
== ignored_reset
)
464 set_state(my_id
, sm
->name
, sm
->sym
, &start_state
);
467 static struct smatch_state
*get_start_state(struct sm_state
*sm
)
469 struct smatch_state
*orig
;
474 orig
= get_state_stree(start_states
, my_id
, sm
->name
, sm
->sym
);
480 static struct expression
*remove_spinlock_check(struct expression
*expr
)
482 if (expr
->type
!= EXPR_CALL
)
484 if (expr
->fn
->type
!= EXPR_SYMBOL
)
486 if (strcmp(expr
->fn
->symbol_name
->name
, "spinlock_check"))
488 expr
= get_argument_from_call_expr(expr
->args
, 0);
492 static struct expression
*filter_kernel_args(struct expression
*arg
)
494 if (arg
->type
== EXPR_PREOP
&& arg
->op
== '&')
495 return strip_expr(arg
->unop
);
496 if (!is_pointer(arg
))
498 return deref_expression(strip_expr(arg
));
501 static char *lock_to_name_sym(struct expression
*expr
, struct symbol
**sym
)
503 expr
= remove_spinlock_check(expr
);
504 expr
= filter_kernel_args(expr
);
505 return expr_to_str_sym(expr
, sym
);
508 static struct smatch_state
*unmatched_state(struct sm_state
*sm
)
513 static void pre_merge_hook(struct sm_state
*cur
, struct sm_state
*other
)
515 if (is_impossible_path())
516 set_state(my_id
, cur
->name
, cur
->sym
, &impossible
);
519 static struct smatch_state
*merge_func(struct smatch_state
*s1
, struct smatch_state
*s2
)
521 if (s1
== &impossible
)
523 if (s2
== &impossible
)
528 static struct sm_state
*get_best_match(const char *key
, int lock_unlock
)
531 struct sm_state
*match
;
533 int start_pos
, state_len
, key_len
, chunks
, i
;
535 if (strncmp(key
, "$->", 3) == 0)
538 key_len
= strlen(key
);
540 for (i
= key_len
- 1; i
> 0; i
--) {
541 if (key
[i
] == '>' || key
[i
] == '.')
545 key_len
= strlen(key
);
550 FOR_EACH_MY_SM(my_id
, __get_cur_stree(), sm
) {
551 if (((lock_unlock
== UNLOCK
|| lock_unlock
== RESTORE
) &&
552 sm
->state
!= &locked
) ||
553 (lock_unlock
== LOCK
&& sm
->state
!= &unlocked
))
555 state_len
= strlen(sm
->name
);
556 if (state_len
< key_len
)
558 start_pos
= state_len
- key_len
;
559 if ((start_pos
== 0 || !isalnum(sm
->name
[start_pos
- 1])) &&
560 strcmp(sm
->name
+ start_pos
, key
) == 0) {
564 } END_FOR_EACH_SM(sm
);
571 static char *use_best_match(const char *key
, int lock_unlock
, struct symbol
**sym
)
573 struct sm_state
*match
;
575 match
= get_best_match(key
, lock_unlock
);
578 return alloc_string(key
);
581 return alloc_string(match
->name
);
584 static void set_start_state(const char *name
, struct symbol
*sym
, struct smatch_state
*start
)
586 struct smatch_state
*orig
;
588 orig
= get_state_stree(start_states
, my_id
, name
, sym
);
590 set_state_stree(&start_states
, my_id
, name
, sym
, start
);
591 else if (orig
!= start
)
592 set_state_stree(&start_states
, my_id
, name
, sym
, &undefined
);
595 static bool common_false_positive(const char *name
)
597 const char *path
, *lname
;
598 int i
, len_total
, len_path
, len_name
, skip
;
603 len_total
= strlen(name
);
604 for (i
= 0; i
< ARRAY_SIZE(false_positives
); i
++) {
605 path
= false_positives
[i
][0];
606 lname
= false_positives
[i
][1];
608 len_path
= strlen(path
);
609 len_name
= strlen(lname
);
611 if (len_name
> len_total
)
613 skip
= len_total
- len_name
;
615 if (strncmp(get_filename(), path
, len_path
) == 0 &&
616 strcmp(name
+ skip
, lname
) == 0)
623 static bool sm_in_start_states(struct sm_state
*sm
)
625 if (!sm
|| !cur_func_sym
)
627 if (sm
->line
== cur_func_sym
->pos
.line
)
632 static void warn_on_double(struct sm_state
*sm
, struct smatch_state
*state
)
634 struct sm_state
*tmp
;
639 FOR_EACH_PTR(sm
->possible
, tmp
) {
640 if (tmp
->state
== state
)
642 } END_FOR_EACH_PTR(tmp
);
646 // FIXME: called with read_lock held
647 // drivers/scsi/aic7xxx/aic7xxx_osm.c:1591 ahc_linux_isr() error: double locked 'flags' (orig line 1584)
648 if (strcmp(sm
->name
, "bottom_half") == 0)
650 if (strstr(sm
->name
, "rcu"))
652 if (common_false_positive(sm
->name
))
655 if (state
== &locked
&& sm_in_start_states(tmp
)) {
656 // sm_warning("called with lock held. '%s'", sm->name);
658 // sm_msg("error: double %s '%s' (orig line %u)",
659 // state->name, sm->name, tmp->line);
663 static bool handle_macro_lock_unlock(void)
665 struct expression
*expr
, *arg
;
666 struct macro_info
*info
;
674 expr
= last_ptr_list((struct ptr_list
*)big_expression_stack
);
675 while (expr
&& expr
->type
== EXPR_ASSIGNMENT
)
676 expr
= strip_expr(expr
->right
);
677 if (!expr
|| expr
->type
!= EXPR_CALL
)
680 macro
= get_macro_name(expr
->pos
);
684 for (i
= 0; i
< ARRAY_SIZE(macro_table
); i
++) {
685 info
= ¯o_table
[i
];
687 if (strcmp(macro
, info
->macro
) != 0)
689 arg
= get_argument_from_call_expr(expr
->args
, info
->param
);
690 name
= expr_to_str_sym(arg
, &sym
);
693 sm
= get_sm_state(my_id
, name
, sym
);
695 if (info
->action
== LOCK
) {
696 if (!get_start_state(sm
))
697 set_start_state(name
, sym
, &unlocked
);
698 if (sm
&& sm
->line
!= expr
->pos
.line
)
699 warn_on_double(sm
, &locked
);
700 set_state(my_id
, name
, sym
, &locked
);
702 if (!get_start_state(sm
))
703 set_start_state(name
, sym
, &locked
);
704 if (sm
&& sm
->line
!= expr
->pos
.line
)
705 warn_on_double(sm
, &unlocked
);
706 set_state(my_id
, name
, sym
, &unlocked
);
716 static bool is_local_IRQ_save(const char *name
, struct symbol
*sym
, struct lock_info
*info
)
718 if (name
&& strcmp(name
, "flags") == 0)
722 if (!sym
->ident
|| strcmp(sym
->ident
->name
, name
) != 0)
726 return strstr(info
->function
, "irq") && strstr(info
->function
, "save");
729 static void do_lock(const char *name
, struct symbol
*sym
, struct lock_info
*info
)
732 bool delete_null
= false;
734 if (!info
&& handle_macro_lock_unlock())
737 add_tracker(&locks
, my_id
, name
, sym
);
739 sm
= get_sm_state(my_id
, name
, sym
);
740 if (!get_start_state(sm
))
741 set_start_state(name
, sym
, &unlocked
);
742 if (!sm
&& !is_local_IRQ_save(name
, sym
, info
) && !sym
) {
743 sm
= get_best_match(name
, LOCK
);
752 warn_on_double(sm
, &locked
);
754 set_state(my_id
, name
, NULL
, &ignore
);
756 set_state(my_id
, name
, sym
, &locked
);
759 static void do_unlock(const char *name
, struct symbol
*sym
, struct lock_info
*info
)
762 bool delete_null
= false;
764 if (__path_is_null())
767 if (!info
&& handle_macro_lock_unlock())
770 add_tracker(&locks
, my_id
, name
, sym
);
771 sm
= get_sm_state(my_id
, name
, sym
);
772 if (!sm
&& !info
&& !is_local_IRQ_save(name
, sym
, info
)) {
773 sm
= get_best_match(name
, UNLOCK
);
782 if (!get_start_state(sm
))
783 set_start_state(name
, sym
, &locked
);
784 warn_on_double(sm
, &unlocked
);
786 set_state(my_id
, name
, NULL
, &ignore
);
787 set_state(my_id
, name
, sym
, &unlocked
);
790 static void do_restore(const char *name
, struct symbol
*sym
, struct lock_info
*info
)
794 if (__path_is_null())
797 sm
= get_sm_state(my_id
, name
, sym
);
798 if (!get_start_state(sm
))
799 set_start_state(name
, sym
, &locked
);
801 add_tracker(&locks
, my_id
, name
, sym
);
802 set_state(my_id
, name
, sym
, &restore
);
805 static int get_db_type(struct sm_state
*sm
)
808 * Bottom half is complicated because it's nestable.
809 * Say it's merged at the start and we lock and unlock then
810 * it should go back to merged.
812 if (sm
->state
== get_start_state(sm
)) {
813 if (sm
->state
== &locked
)
815 if (sm
->state
== &unlocked
)
816 return KNOWN_UNLOCKED
;
819 if (sm
->state
== &locked
)
821 if (sm
->state
== &unlocked
)
823 if (sm
->state
== &restore
)
828 static void match_return_info(int return_id
, char *return_ranges
, struct expression
*expr
)
830 struct smatch_state
*start
;
832 const char *param_name
;
835 FOR_EACH_MY_SM(my_id
, __get_cur_stree(), sm
) {
836 if (sm
->state
!= &locked
&&
837 sm
->state
!= &unlocked
&&
838 sm
->state
!= &restore
)
840 if (sm
->name
[0] == '$')
844 * If the state is locked at the end, that doesn't mean
845 * anything. It could be been locked at the start. Or
846 * it could be &merged at the start but its locked now
847 * because of implications and not because we set the
850 * This is slightly a hack, but when we change the state, we
851 * call set_start_state() so if get_start_state() returns NULL
852 * that means we haven't manually the locked state.
854 start
= get_start_state(sm
);
855 if (sm
->state
== &restore
) {
856 if (start
!= &locked
)
858 } else if (!start
|| sm
->state
== start
)
859 continue; /* !start means it was passed in */
861 param
= get_param_key_from_sm(sm
, expr
, ¶m_name
);
862 sql_insert_return_states(return_id
, return_ranges
,
864 param
, param_name
, "");
865 } END_FOR_EACH_SM(sm
);
868 static int sm_both_locked_and_unlocked(struct sm_state
*sm
)
872 struct sm_state
*tmp
;
874 if (sm
->state
!= &merged
)
877 FOR_EACH_PTR(sm
->possible
, tmp
) {
878 if (tmp
->state
== &locked
)
880 if (tmp
->state
== &unlocked
)
882 } END_FOR_EACH_PTR(tmp
);
884 return is_locked
&& is_unlocked
;
888 ERR_PTR
, VALID_PTR
, NEGATIVE
, ZERO
, POSITIVE
, NUM_BUCKETS
,
891 static bool is_EINTR(struct range_list
*rl
)
895 if (!rl_to_sval(rl
, &sval
))
897 return sval
.value
== -4;
900 static int success_fail_positive(struct range_list
*rl
)
902 /* void returns are the same as success (zero in the kernel) */
906 if (rl_type(rl
)->type
!= SYM_PTR
&&
908 sval_is_negative(rl_min(rl
)))
911 if (rl_min(rl
).value
== 0 && rl_max(rl
).value
== 0)
914 if (is_err_ptr(rl_min(rl
)) &&
915 is_err_ptr(rl_max(rl
)))
919 * Trying to match ERR_PTR(ret) but without the expression struct.
922 if (type_bits(&long_ctype
) == 64 &&
923 rl_type(rl
)->type
== SYM_PTR
&&
924 rl_min(rl
).value
== INT_MIN
)
930 static bool sym_in_lock_table(struct symbol
*sym
)
934 if (!sym
|| !sym
->ident
)
937 for (i
= 0; lock_table
[i
].function
!= NULL
; i
++) {
938 if (strcmp(lock_table
[i
].function
, sym
->ident
->name
) == 0)
944 static bool func_in_lock_table(struct expression
*expr
)
946 if (expr
->type
!= EXPR_SYMBOL
)
948 return sym_in_lock_table(expr
->symbol
);
951 static void check_lock(char *name
, struct symbol
*sym
)
953 struct range_list
*locked_lines
= NULL
;
954 struct range_list
*unlocked_lines
= NULL
;
955 int locked_buckets
[NUM_BUCKETS
] = {};
956 int unlocked_buckets
[NUM_BUCKETS
] = {};
957 struct stree
*stree
, *orig
;
958 struct sm_state
*return_sm
;
960 sval_t line
= sval_type_val(&int_ctype
, 0);
964 if (sym_in_lock_table(cur_func_sym
))
967 FOR_EACH_PTR(get_all_return_strees(), stree
) {
968 orig
= __swap_cur_stree(stree
);
970 if (is_impossible_path())
973 return_sm
= get_sm_state(RETURN_ID
, "return_ranges", NULL
);
976 line
.value
= return_sm
->line
;
978 sm
= get_sm_state(my_id
, name
, sym
);
982 if (parent_is_gone_var_sym(sm
->name
, sm
->sym
))
985 if (sm
->state
!= &locked
&&
986 sm
->state
!= &unlocked
&&
987 sm
->state
!= &restore
)
990 if ((sm
->state
== &unlocked
|| sm
->state
== &restore
) &&
991 is_EINTR(estate_rl(return_sm
->state
)))
994 bucket
= success_fail_positive(estate_rl(return_sm
->state
));
995 if (sm
->state
== &locked
) {
996 add_range(&locked_lines
, line
, line
);
997 locked_buckets
[bucket
] = true;
999 if (sm
->state
== &unlocked
|| sm
->state
== &restore
) {
1000 add_range(&unlocked_lines
, line
, line
);
1001 unlocked_buckets
[bucket
] = true;
1004 __swap_cur_stree(orig
);
1005 } END_FOR_EACH_PTR(stree
);
1008 if (!locked_lines
|| !unlocked_lines
)
1011 for (i
= 0; i
< NUM_BUCKETS
; i
++) {
1012 if (locked_buckets
[i
] && unlocked_buckets
[i
])
1015 if (locked_buckets
[NEGATIVE
] &&
1016 (unlocked_buckets
[ZERO
] || unlocked_buckets
[POSITIVE
]))
1019 if (locked_buckets
[ERR_PTR
])
1025 sm_msg("warn: inconsistent returns '%s'.", name
);
1026 sm_printf(" Locked on : %s\n", show_rl(locked_lines
));
1027 sm_printf(" Unlocked on: %s\n", show_rl(unlocked_lines
));
1030 static void match_func_end(struct symbol
*sym
)
1032 struct tracker
*tracker
;
1034 FOR_EACH_PTR(locks
, tracker
) {
1035 check_lock(tracker
->name
, tracker
->sym
);
1036 } END_FOR_EACH_PTR(tracker
);
1039 static void db_param_locked_unlocked(struct expression
*expr
, int param
, const char *key
, int lock_unlock
, struct lock_info
*info
)
1041 struct expression
*call
, *arg
;
1045 if (info
&& info
->action
== IGNORE_LOCK
)
1049 while (call
->type
== EXPR_ASSIGNMENT
)
1050 call
= strip_expr(call
->right
);
1051 if (call
->type
!= EXPR_CALL
)
1054 if (!info
&& func_in_lock_table(call
->fn
))
1059 name
= use_best_match(key
, lock_unlock
, &sym
);
1061 name
= alloc_string(info
->key
);
1064 } else if (param
== -1) {
1065 if (expr
->type
!= EXPR_ASSIGNMENT
)
1067 ignored_reset
= expr
->left
;
1069 name
= get_variable_from_key(expr
->left
, key
, &sym
);
1073 arg
= get_argument_from_call_expr(call
->args
, param
);
1077 arg
= remove_spinlock_check(arg
);
1078 name
= get_variable_from_key(arg
, key
, &sym
);
1086 if (lock_unlock
== LOCK
)
1087 do_lock(name
, sym
, info
);
1088 else if (lock_unlock
== UNLOCK
)
1089 do_unlock(name
, sym
, info
);
1090 else if (lock_unlock
== RESTORE
)
1091 do_restore(name
, sym
, info
);
1097 static void db_param_locked(struct expression
*expr
, int param
, char *key
, char *value
)
1099 db_param_locked_unlocked(expr
, param
, key
, LOCK
, NULL
);
1102 static void db_param_unlocked(struct expression
*expr
, int param
, char *key
, char *value
)
1104 db_param_locked_unlocked(expr
, param
, key
, UNLOCK
, NULL
);
1107 static void db_param_restore(struct expression
*expr
, int param
, char *key
, char *value
)
1109 db_param_locked_unlocked(expr
, param
, key
, RESTORE
, NULL
);
1112 static void match_lock_unlock(const char *fn
, struct expression
*expr
, void *data
)
1114 struct lock_info
*info
= data
;
1115 struct expression
*parent
;
1117 if (info
->arg
== -1) {
1118 parent
= expr_get_parent_expr(expr
);
1119 while (parent
&& parent
->type
!= EXPR_ASSIGNMENT
)
1120 parent
= expr_get_parent_expr(parent
);
1121 if (!parent
|| parent
->type
!= EXPR_ASSIGNMENT
)
1126 db_param_locked_unlocked(expr
, info
->arg
, info
->key
, info
->action
, info
);
1129 static void match_lock_held(const char *fn
, struct expression
*call_expr
,
1130 struct expression
*assign_expr
, void *data
)
1132 struct lock_info
*info
= data
;
1134 db_param_locked_unlocked(assign_expr
?: call_expr
, info
->arg
, info
->key
, info
->action
, info
);
1137 static void match_assign(struct expression
*expr
)
1139 struct smatch_state
*state
;
1141 /* This is only for the DB */
1142 if (!__in_fake_var_assign
)
1144 state
= get_state_expr(my_id
, expr
->right
);
1147 set_state_expr(my_id
, expr
->left
, state
);
1150 static struct stree
*printed
;
1151 static void call_info_callback(struct expression
*call
, int param
, char *printed_name
, struct sm_state
*sm
)
1153 int locked_type
= 0;
1155 if (sm
->state
== &locked
)
1157 else if (sm
->state
== &unlocked
)
1158 locked_type
= UNLOCK
;
1159 else if (slist_has_state(sm
->possible
, &locked
) ||
1160 slist_has_state(sm
->possible
, &half_locked
))
1161 locked_type
= HALF_LOCKED
;
1165 avl_insert(&printed
, sm
);
1166 sql_insert_caller_info(call
, locked_type
, param
, printed_name
, "");
1169 static void match_call_info(struct expression
*expr
)
1171 struct sm_state
*sm
;
1175 FOR_EACH_MY_SM(my_id
, __get_cur_stree(), sm
) {
1176 if (sm
->state
== &locked
)
1178 else if (sm
->state
== &half_locked
||
1179 slist_has_state(sm
->possible
, &locked
))
1180 locked_type
= HALF_LOCKED
;
1184 if (avl_lookup(printed
, sm
))
1187 if (strcmp(sm
->name
, "bottom_half") == 0)
1189 else if (strcmp(sm
->name
, "rcu_read") == 0)
1190 name
= "rcu_read_lock";
1194 if (strncmp(name
, "__fake_param", 12) == 0 ||
1198 sql_insert_caller_info(expr
, locked_type
, -2, name
, "");
1199 } END_FOR_EACH_SM(sm
);
1200 free_stree(&printed
);
1203 static void set_locked(const char *name
, struct symbol
*sym
, char *value
)
1205 set_state(my_id
, name
, sym
, &locked
);
1208 static void set_half_locked(const char *name
, struct symbol
*sym
, char *value
)
1210 set_state(my_id
, name
, sym
, &half_locked
);
1213 static void set_unlocked(const char *name
, struct symbol
*sym
, char *value
)
1215 set_state(my_id
, name
, sym
, &unlocked
);
1218 static void match_after_func(struct symbol
*sym
)
1220 free_stree(&start_states
);
1223 static void match_dma_resv_lock_NULL(const char *fn
, struct expression
*call_expr
,
1224 struct expression
*assign_expr
, void *_index
)
1226 struct expression
*lock
, *ctx
;
1230 lock
= get_argument_from_call_expr(call_expr
->args
, 0);
1231 ctx
= get_argument_from_call_expr(call_expr
->args
, 1);
1232 if (!expr_is_zero(ctx
))
1235 lock_name
= lock_to_name_sym(lock
, &sym
);
1236 if (!lock_name
|| !sym
)
1238 do_lock(lock_name
, sym
, NULL
);
1240 free_string(lock_name
);
1243 /* print_held_locks() is used in check_call_tree.c */
1244 void print_held_locks(void)
1246 struct stree
*stree
;
1247 struct sm_state
*sm
;
1250 stree
= __get_cur_stree();
1251 FOR_EACH_MY_SM(my_id
, stree
, sm
) {
1252 if (sm
->state
!= &locked
)
1256 sm_printf("'%s'", sm
->name
);
1257 } END_FOR_EACH_SM(sm
);
1260 static void load_table(struct lock_info
*lock_table
)
1264 for (i
= 0; lock_table
[i
].function
!= NULL
; i
++) {
1265 struct lock_info
*lock
= &lock_table
[i
];
1267 if (lock
->call_back
) {
1268 add_function_hook(lock
->function
, lock
->call_back
, lock
);
1269 } else if (lock
->implies_start
) {
1270 return_implies_state_sval(lock
->function
,
1271 *lock
->implies_start
,
1273 &match_lock_held
, lock
);
1275 add_function_hook(lock
->function
, &match_lock_unlock
, lock
);
1280 static bool is_smp_config(void)
1284 id
= built_in_ident("CONFIG_SMP");
1285 return !!lookup_symbol(id
, NS_MACRO
);
1288 void check_locking(int id
)
1292 if (option_project
!= PROJ_KERNEL
)
1295 if (!is_smp_config())
1298 load_table(lock_table
);
1300 set_dynamic_states(my_id
);
1301 add_unmatched_state_hook(my_id
, &unmatched_state
);
1302 add_pre_merge_hook(my_id
, &pre_merge_hook
);
1303 add_merge_hook(my_id
, &merge_func
);
1304 add_modification_hook(my_id
, &reset
);
1306 add_hook(&match_assign
, ASSIGNMENT_HOOK
);
1307 add_hook(&match_func_end
, END_FUNC_HOOK
);
1309 add_hook(&match_after_func
, AFTER_FUNC_HOOK
);
1310 add_function_data((unsigned long *)&start_states
);
1312 add_caller_info_callback(my_id
, call_info_callback
);
1313 add_hook(&match_call_info
, FUNCTION_CALL_HOOK
);
1315 add_split_return_callback(match_return_info
);
1316 select_return_states_hook(LOCK
, &db_param_locked
);
1317 select_return_states_hook(UNLOCK
, &db_param_unlocked
);
1318 select_return_states_hook(RESTORE
, &db_param_restore
);
1320 select_caller_name_sym(set_locked
, LOCK
);
1321 select_caller_name_sym(set_half_locked
, HALF_LOCKED
);
1322 select_caller_name_sym(set_unlocked
, UNLOCK
);
1324 return_implies_state("dma_resv_lock", -4095, -1, &match_dma_resv_lock_NULL
, 0);