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"
52 const char *get_lock_name(enum lock_type type
)
54 static const char *names
[] = {
55 [spin_lock
] = "spin_lock",
56 [read_lock
] = "read_lock",
57 [write_lock
] = "write_lock",
59 [bottom_half
] = "bottom_half",
62 [prepare_lock
] = "prepare_lock",
63 [enable_lock
] = "enable_lock",
86 enum return_type return_type
;
89 static struct lock_info lock_table
[] = {
90 {"spin_lock", LOCK
, spin_lock
, 0, ret_any
},
91 {"spin_unlock", UNLOCK
, spin_lock
, 0, ret_any
},
92 {"spin_lock_nested", LOCK
, spin_lock
, 0, ret_any
},
93 {"_spin_lock", LOCK
, spin_lock
, 0, ret_any
},
94 {"_spin_unlock", UNLOCK
, spin_lock
, 0, ret_any
},
95 {"_spin_lock_nested", LOCK
, spin_lock
, 0, ret_any
},
96 {"__spin_lock", LOCK
, spin_lock
, 0, ret_any
},
97 {"__spin_unlock", UNLOCK
, spin_lock
, 0, ret_any
},
98 {"__spin_lock_nested", LOCK
, spin_lock
, 0, ret_any
},
99 {"raw_spin_lock", LOCK
, spin_lock
, 0, ret_any
},
100 {"raw_spin_unlock", UNLOCK
, spin_lock
, 0, ret_any
},
101 {"_raw_spin_lock", LOCK
, spin_lock
, 0, ret_any
},
102 {"_raw_spin_lock_nested", LOCK
, spin_lock
, 0, ret_any
},
103 {"_raw_spin_unlock", UNLOCK
, spin_lock
, 0, ret_any
},
104 {"__raw_spin_lock", LOCK
, spin_lock
, 0, ret_any
},
105 {"__raw_spin_unlock", UNLOCK
, spin_lock
, 0, ret_any
},
107 {"spin_lock_irq", LOCK
, spin_lock
, 0, ret_any
},
108 {"spin_unlock_irq", UNLOCK
, spin_lock
, 0, ret_any
},
109 {"_spin_lock_irq", LOCK
, spin_lock
, 0, ret_any
},
110 {"_spin_unlock_irq", UNLOCK
, spin_lock
, 0, ret_any
},
111 {"__spin_lock_irq", LOCK
, spin_lock
, 0, ret_any
},
112 {"__spin_unlock_irq", UNLOCK
, spin_lock
, 0, ret_any
},
113 {"_raw_spin_lock_irq", LOCK
, spin_lock
, 0, ret_any
},
114 {"_raw_spin_unlock_irq", UNLOCK
, spin_lock
, 0, ret_any
},
115 {"__raw_spin_unlock_irq", UNLOCK
, spin_lock
, 0, ret_any
},
116 {"spin_lock_irqsave", LOCK
, spin_lock
, 0, ret_any
},
117 {"spin_unlock_irqrestore", UNLOCK
, spin_lock
, 0, ret_any
},
118 {"_spin_lock_irqsave", LOCK
, spin_lock
, 0, ret_any
},
119 {"_spin_unlock_irqrestore", UNLOCK
, spin_lock
, 0, ret_any
},
120 {"__spin_lock_irqsave", LOCK
, spin_lock
, 0, ret_any
},
121 {"__spin_unlock_irqrestore", UNLOCK
, spin_lock
, 0, ret_any
},
122 {"_raw_spin_lock_irqsave", LOCK
, spin_lock
, 0, ret_any
},
123 {"_raw_spin_unlock_irqrestore", UNLOCK
, spin_lock
, 0, ret_any
},
124 {"__raw_spin_lock_irqsave", LOCK
, spin_lock
, 0, ret_any
},
125 {"__raw_spin_unlock_irqrestore", UNLOCK
, spin_lock
, 0, ret_any
},
126 {"spin_lock_irqsave_nested", LOCK
, spin_lock
, 0, ret_any
},
127 {"_spin_lock_irqsave_nested", LOCK
, spin_lock
, 0, ret_any
},
128 {"__spin_lock_irqsave_nested", LOCK
, spin_lock
, 0, ret_any
},
129 {"_raw_spin_lock_irqsave_nested", LOCK
, spin_lock
, 0, ret_any
},
130 {"spin_lock_bh", LOCK
, spin_lock
, 0, ret_any
},
131 {"spin_unlock_bh", UNLOCK
, spin_lock
, 0, ret_any
},
132 {"_spin_lock_bh", LOCK
, spin_lock
, 0, ret_any
},
133 {"_spin_unlock_bh", UNLOCK
, spin_lock
, 0, ret_any
},
134 {"__spin_lock_bh", LOCK
, spin_lock
, 0, ret_any
},
135 {"__spin_unlock_bh", UNLOCK
, spin_lock
, 0, ret_any
},
137 {"spin_trylock", LOCK
, spin_lock
, 0, ret_one
},
138 {"_spin_trylock", LOCK
, spin_lock
, 0, ret_one
},
139 {"__spin_trylock", LOCK
, spin_lock
, 0, ret_one
},
140 {"raw_spin_trylock", LOCK
, spin_lock
, 0, ret_one
},
141 {"_raw_spin_trylock", LOCK
, spin_lock
, 0, ret_one
},
142 {"spin_trylock_irq", LOCK
, spin_lock
, 0, ret_one
},
143 {"spin_trylock_irqsave", LOCK
, spin_lock
, 0, ret_one
},
144 {"spin_trylock_bh", LOCK
, spin_lock
, 0, ret_one
},
145 {"_spin_trylock_bh", LOCK
, spin_lock
, 0, ret_one
},
146 {"__spin_trylock_bh", LOCK
, spin_lock
, 0, ret_one
},
147 {"__raw_spin_trylock", LOCK
, spin_lock
, 0, ret_one
},
148 {"_atomic_dec_and_lock", LOCK
, spin_lock
, 1, ret_one
},
150 {"read_lock", LOCK
, read_lock
, 0, ret_any
},
151 {"down_read", LOCK
, read_lock
, 0, ret_any
},
152 {"down_read_nested", LOCK
, read_lock
, 0, ret_any
},
153 {"down_read_trylock", LOCK
, read_lock
, 0, ret_one
},
154 {"up_read", UNLOCK
, read_lock
, 0, ret_any
},
155 {"read_unlock", UNLOCK
, read_lock
, 0, ret_any
},
156 {"_read_lock", LOCK
, read_lock
, 0, ret_any
},
157 {"_read_unlock", UNLOCK
, read_lock
, 0, ret_any
},
158 {"__read_lock", LOCK
, read_lock
, 0, ret_any
},
159 {"__read_unlock", UNLOCK
, read_lock
, 0, ret_any
},
160 {"_raw_read_lock", LOCK
, read_lock
, 0, ret_any
},
161 {"_raw_read_unlock", UNLOCK
, read_lock
, 0, ret_any
},
162 {"__raw_read_lock", LOCK
, read_lock
, 0, ret_any
},
163 {"__raw_read_unlock", UNLOCK
, read_lock
, 0, ret_any
},
164 {"read_lock_irq", LOCK
, read_lock
, 0, ret_any
},
165 {"read_unlock_irq" , UNLOCK
, read_lock
, 0, ret_any
},
166 {"_read_lock_irq", LOCK
, read_lock
, 0, ret_any
},
167 {"_read_unlock_irq", UNLOCK
, read_lock
, 0, ret_any
},
168 {"__read_lock_irq", LOCK
, read_lock
, 0, ret_any
},
169 {"__read_unlock_irq", UNLOCK
, read_lock
, 0, ret_any
},
170 {"_raw_read_unlock_irq", UNLOCK
, read_lock
, 0, ret_any
},
171 {"_raw_read_lock_irq", LOCK
, read_lock
, 0, ret_any
},
172 {"_raw_read_lock_bh", LOCK
, read_lock
, 0, ret_any
},
173 {"_raw_read_unlock_bh", UNLOCK
, read_lock
, 0, ret_any
},
174 {"read_lock_irqsave", LOCK
, read_lock
, 0, ret_any
},
175 {"read_unlock_irqrestore", UNLOCK
, read_lock
, 0, ret_any
},
176 {"_read_lock_irqsave", LOCK
, read_lock
, 0, ret_any
},
177 {"_read_unlock_irqrestore", UNLOCK
, read_lock
, 0, ret_any
},
178 {"__read_lock_irqsave", LOCK
, read_lock
, 0, ret_any
},
179 {"__read_unlock_irqrestore", UNLOCK
, read_lock
, 0, ret_any
},
180 {"read_lock_bh", LOCK
, read_lock
, 0, ret_any
},
181 {"read_unlock_bh", UNLOCK
, read_lock
, 0, ret_any
},
182 {"_read_lock_bh", LOCK
, read_lock
, 0, ret_any
},
183 {"_read_unlock_bh", UNLOCK
, read_lock
, 0, ret_any
},
184 {"__read_lock_bh", LOCK
, read_lock
, 0, ret_any
},
185 {"__read_unlock_bh", UNLOCK
, read_lock
, 0, ret_any
},
186 {"__raw_read_lock_bh", LOCK
, read_lock
, 0, ret_any
},
187 {"__raw_read_unlock_bh", UNLOCK
, read_lock
, 0, ret_any
},
189 {"_raw_read_lock_irqsave", LOCK
, read_lock
, 0, ret_any
},
190 {"_raw_read_lock_irqsave", LOCK
, irq
, RETURN_VAL
, ret_any
},
191 {"_raw_read_unlock_irqrestore", UNLOCK
, read_lock
, 0, ret_any
},
192 {"_raw_read_unlock_irqrestore", RESTORE
, irq
, 1, ret_any
},
193 {"_raw_spin_lock_bh", LOCK
, read_lock
, 0, ret_any
},
194 {"_raw_spin_lock_bh", LOCK
, bottom_half
, NO_ARG
, ret_any
},
195 {"_raw_spin_lock_nest_lock", LOCK
, read_lock
, 0, ret_any
},
196 {"_raw_spin_unlock_bh", UNLOCK
, read_lock
, 0, ret_any
},
197 {"_raw_spin_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
198 {"_raw_write_lock_irqsave", LOCK
, write_lock
, 0, ret_any
},
199 {"_raw_write_lock_irqsave", LOCK
, irq
, RETURN_VAL
, ret_any
},
200 {"_raw_write_unlock_irqrestore", UNLOCK
, write_lock
, 0, ret_any
},
201 {"_raw_write_unlock_irqrestore", RESTORE
, irq
, 1, ret_any
},
202 {"__raw_write_unlock_irqrestore", UNLOCK
, write_lock
, 0, ret_any
},
203 {"__raw_write_unlock_irqrestore", RESTORE
, irq
, 1, ret_any
},
205 {"generic__raw_read_trylock", LOCK
, read_lock
, 0, ret_one
},
206 {"read_trylock", LOCK
, read_lock
, 0, ret_one
},
207 {"_read_trylock", LOCK
, read_lock
, 0, ret_one
},
208 {"raw_read_trylock", LOCK
, read_lock
, 0, ret_one
},
209 {"_raw_read_trylock", LOCK
, read_lock
, 0, ret_one
},
210 {"__raw_read_trylock", LOCK
, read_lock
, 0, ret_one
},
211 {"__read_trylock", LOCK
, read_lock
, 0, ret_one
},
213 {"write_lock", LOCK
, write_lock
, 0, ret_any
},
214 {"down_write", LOCK
, write_lock
, 0, ret_any
},
215 {"down_write_nested", LOCK
, write_lock
, 0, ret_any
},
216 {"up_write", UNLOCK
, write_lock
, 0, ret_any
},
217 {"write_unlock", UNLOCK
, write_lock
, 0, ret_any
},
218 {"_write_lock", LOCK
, write_lock
, 0, ret_any
},
219 {"_write_unlock", UNLOCK
, write_lock
, 0, ret_any
},
220 {"__write_lock", LOCK
, write_lock
, 0, ret_any
},
221 {"__write_unlock", UNLOCK
, write_lock
, 0, ret_any
},
222 {"write_lock_irq", LOCK
, write_lock
, 0, ret_any
},
223 {"write_unlock_irq", UNLOCK
, write_lock
, 0, ret_any
},
224 {"_write_lock_irq", LOCK
, write_lock
, 0, ret_any
},
225 {"_write_unlock_irq", UNLOCK
, write_lock
, 0, ret_any
},
226 {"__write_lock_irq", LOCK
, write_lock
, 0, ret_any
},
227 {"__write_unlock_irq", UNLOCK
, write_lock
, 0, ret_any
},
228 {"_raw_write_unlock_irq", UNLOCK
, write_lock
, 0, ret_any
},
229 {"write_lock_irqsave", LOCK
, write_lock
, 0, ret_any
},
230 {"write_unlock_irqrestore", UNLOCK
, write_lock
, 0, ret_any
},
231 {"_write_lock_irqsave", LOCK
, write_lock
, 0, ret_any
},
232 {"_write_unlock_irqrestore", UNLOCK
, write_lock
, 0, ret_any
},
233 {"__write_lock_irqsave", LOCK
, write_lock
, 0, ret_any
},
234 {"__write_unlock_irqrestore", UNLOCK
, write_lock
, 0, ret_any
},
235 {"write_lock_bh", LOCK
, write_lock
, 0, ret_any
},
236 {"write_unlock_bh", UNLOCK
, write_lock
, 0, ret_any
},
237 {"_write_lock_bh", LOCK
, write_lock
, 0, ret_any
},
238 {"_write_unlock_bh", UNLOCK
, write_lock
, 0, ret_any
},
239 {"__write_lock_bh", LOCK
, write_lock
, 0, ret_any
},
240 {"__write_unlock_bh", UNLOCK
, write_lock
, 0, ret_any
},
241 {"_raw_write_lock", LOCK
, write_lock
, 0, ret_any
},
242 {"__raw_write_lock", LOCK
, write_lock
, 0, ret_any
},
243 {"_raw_write_unlock", UNLOCK
, write_lock
, 0, ret_any
},
244 {"__raw_write_unlock", UNLOCK
, write_lock
, 0, ret_any
},
245 {"_raw_write_lock_bh", LOCK
, write_lock
, 0, ret_any
},
246 {"_raw_write_unlock_bh", UNLOCK
, write_lock
, 0, ret_any
},
247 {"_raw_write_lock_irq", LOCK
, write_lock
, 0, ret_any
},
249 {"write_trylock", LOCK
, write_lock
, 0, ret_one
},
250 {"_write_trylock", LOCK
, write_lock
, 0, ret_one
},
251 {"raw_write_trylock", LOCK
, write_lock
, 0, ret_one
},
252 {"_raw_write_trylock", LOCK
, write_lock
, 0, ret_one
},
253 {"__write_trylock", LOCK
, write_lock
, 0, ret_one
},
254 {"__raw_write_trylock", LOCK
, write_lock
, 0, ret_one
},
255 {"down_write_trylock", LOCK
, write_lock
, 0, ret_one
},
256 {"down_write_killable", LOCK
, write_lock
, 0, ret_zero
},
258 {"down", LOCK
, sem
, 0, ret_any
},
259 {"up", UNLOCK
, sem
, 0, ret_any
},
260 {"down_trylock", LOCK
, sem
, 0, ret_zero
},
261 {"down_timeout", LOCK
, sem
, 0, ret_zero
},
262 {"down_interruptible", LOCK
, sem
, 0, ret_zero
},
263 {"down_killable", LOCK
, sem
, 0, ret_zero
},
266 {"mutex_lock", LOCK
, mutex
, 0, ret_any
},
267 {"mutex_unlock", UNLOCK
, mutex
, 0, ret_any
},
268 {"mutex_lock_nested", LOCK
, mutex
, 0, ret_any
},
269 {"mutex_lock_io", LOCK
, mutex
, 0, ret_any
},
270 {"mutex_lock_io_nested", LOCK
, mutex
, 0, ret_any
},
272 {"mutex_lock_interruptible", LOCK
, mutex
, 0, ret_zero
},
273 {"mutex_lock_interruptible_nested", LOCK
, mutex
, 0, ret_zero
},
274 {"mutex_lock_killable", LOCK
, mutex
, 0, ret_zero
},
275 {"mutex_lock_killable_nested", LOCK
, mutex
, 0, ret_zero
},
277 {"mutex_trylock", LOCK
, mutex
, 0, ret_one
},
279 {"ww_mutex_lock", LOCK
, mutex
, 0, ret_any
},
280 {"__ww_mutex_lock", LOCK
, mutex
, 0, ret_any
},
281 {"ww_mutex_lock_interruptible", LOCK
, mutex
, 0, ret_zero
},
282 {"ww_mutex_unlock", UNLOCK
, mutex
, 0, ret_any
},
284 {"raw_local_irq_disable", LOCK
, irq
, NO_ARG
, ret_any
},
285 {"raw_local_irq_enable", UNLOCK
, irq
, NO_ARG
, ret_any
},
286 {"spin_lock_irq", LOCK
, irq
, NO_ARG
, ret_any
},
287 {"spin_unlock_irq", UNLOCK
, irq
, NO_ARG
, ret_any
},
288 {"_spin_lock_irq", LOCK
, irq
, NO_ARG
, ret_any
},
289 {"_spin_unlock_irq", UNLOCK
, irq
, NO_ARG
, ret_any
},
290 {"__spin_lock_irq", LOCK
, irq
, NO_ARG
, ret_any
},
291 {"__spin_unlock_irq", UNLOCK
, irq
, NO_ARG
, ret_any
},
292 {"_raw_spin_lock_irq", LOCK
, irq
, NO_ARG
, ret_any
},
293 {"_raw_spin_unlock_irq", UNLOCK
, irq
, NO_ARG
, ret_any
},
294 {"__raw_spin_unlock_irq", UNLOCK
, irq
, NO_ARG
, ret_any
},
295 {"spin_trylock_irq", LOCK
, irq
, NO_ARG
, ret_one
},
296 {"read_lock_irq", LOCK
, irq
, NO_ARG
, ret_any
},
297 {"read_unlock_irq", UNLOCK
, irq
, NO_ARG
, ret_any
},
298 {"_read_lock_irq", LOCK
, irq
, NO_ARG
, ret_any
},
299 {"_read_unlock_irq", UNLOCK
, irq
, NO_ARG
, ret_any
},
300 {"__read_lock_irq", LOCK
, irq
, NO_ARG
, ret_any
},
301 {"_raw_read_lock_irq", LOCK
, irq
, NO_ARG
, ret_any
},
302 {"__read_unlock_irq", UNLOCK
, irq
, NO_ARG
, ret_any
},
303 {"_raw_read_unlock_irq", UNLOCK
, irq
, NO_ARG
, ret_any
},
304 {"write_lock_irq", LOCK
, irq
, NO_ARG
, ret_any
},
305 {"write_unlock_irq", UNLOCK
, irq
, NO_ARG
, ret_any
},
306 {"_write_lock_irq", LOCK
, irq
, NO_ARG
, ret_any
},
307 {"_write_unlock_irq", UNLOCK
, irq
, NO_ARG
, ret_any
},
308 {"__write_lock_irq", LOCK
, irq
, NO_ARG
, ret_any
},
309 {"__write_unlock_irq", UNLOCK
, irq
, NO_ARG
, ret_any
},
310 {"_raw_write_lock_irq", LOCK
, irq
, NO_ARG
, ret_any
},
311 {"_raw_write_unlock_irq", UNLOCK
, irq
, NO_ARG
, ret_any
},
313 {"arch_local_irq_save", LOCK
, irq
, RETURN_VAL
, ret_any
},
314 {"arch_local_irq_restore", RESTORE
, irq
, 0, ret_any
},
315 {"__raw_local_irq_save", LOCK
, irq
, RETURN_VAL
, ret_any
},
316 {"raw_local_irq_restore", RESTORE
, irq
, 0, ret_any
},
317 {"spin_lock_irqsave_nested", LOCK
, irq
, RETURN_VAL
, ret_any
},
318 {"spin_lock_irqsave", LOCK
, irq
, 1, ret_any
},
319 {"spin_unlock_irqrestore", RESTORE
, irq
, 1, ret_any
},
320 {"_spin_lock_irqsave_nested", LOCK
, irq
, RETURN_VAL
, ret_any
},
321 {"_spin_lock_irqsave", LOCK
, irq
, RETURN_VAL
, ret_any
},
322 {"_spin_lock_irqsave", LOCK
, irq
, 1, ret_any
},
323 {"_spin_unlock_irqrestore", RESTORE
, irq
, 1, ret_any
},
324 {"__spin_lock_irqsave_nested", LOCK
, irq
, 1, ret_any
},
325 {"__spin_lock_irqsave", LOCK
, irq
, 1, ret_any
},
326 {"__spin_unlock_irqrestore", RESTORE
, irq
, 1, ret_any
},
327 {"_raw_spin_lock_irqsave", LOCK
, irq
, RETURN_VAL
, ret_any
},
328 {"_raw_spin_lock_irqsave", LOCK
, irq
, 1, ret_any
},
329 {"_raw_spin_unlock_irqrestore", RESTORE
, irq
, 1, ret_any
},
330 {"__raw_spin_lock_irqsave", LOCK
, irq
, RETURN_VAL
, ret_any
},
331 {"__raw_spin_unlock_irqrestore", RESTORE
, irq
, 1, ret_any
},
332 {"_raw_spin_lock_irqsave_nested", LOCK
, irq
, RETURN_VAL
, ret_any
},
333 {"spin_trylock_irqsave", LOCK
, irq
, 1, ret_one
},
334 {"read_lock_irqsave", LOCK
, irq
, RETURN_VAL
, ret_any
},
335 {"read_lock_irqsave", LOCK
, irq
, 1, ret_any
},
336 {"read_unlock_irqrestore", RESTORE
, irq
, 1, ret_any
},
337 {"_read_lock_irqsave", LOCK
, irq
, RETURN_VAL
, ret_any
},
338 {"_read_lock_irqsave", LOCK
, irq
, 1, ret_any
},
339 {"_read_unlock_irqrestore", RESTORE
, irq
, 1, ret_any
},
340 {"__read_lock_irqsave", LOCK
, irq
, RETURN_VAL
, ret_any
},
341 {"__read_unlock_irqrestore", RESTORE
, irq
, 1, ret_any
},
342 {"write_lock_irqsave", LOCK
, irq
, RETURN_VAL
, ret_any
},
343 {"write_lock_irqsave", LOCK
, irq
, 1, ret_any
},
344 {"write_unlock_irqrestore", RESTORE
, irq
, 1, ret_any
},
345 {"_write_lock_irqsave", LOCK
, irq
, RETURN_VAL
, ret_any
},
346 {"_write_lock_irqsave", LOCK
, irq
, 1, ret_any
},
347 {"_write_unlock_irqrestore", RESTORE
, irq
, 1, ret_any
},
348 {"__write_lock_irqsave", LOCK
, irq
, RETURN_VAL
, ret_any
},
349 {"__write_unlock_irqrestore", RESTORE
, irq
, 1, ret_any
},
351 {"local_bh_disable", LOCK
, bottom_half
, NO_ARG
, ret_any
},
352 {"_local_bh_disable", LOCK
, bottom_half
, NO_ARG
, ret_any
},
353 {"__local_bh_disable", LOCK
, bottom_half
, NO_ARG
, ret_any
},
354 {"local_bh_enable", UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
355 {"_local_bh_enable", UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
356 {"__local_bh_enable", UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
357 {"spin_lock_bh", LOCK
, bottom_half
, NO_ARG
, ret_any
},
358 {"spin_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
359 {"_spin_lock_bh", LOCK
, bottom_half
, NO_ARG
, ret_any
},
360 {"_spin_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
361 {"__spin_lock_bh", LOCK
, bottom_half
, NO_ARG
, ret_any
},
362 {"__spin_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
363 {"read_lock_bh", LOCK
, bottom_half
, NO_ARG
, ret_any
},
364 {"read_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
365 {"_read_lock_bh", LOCK
, bottom_half
, NO_ARG
, ret_any
},
366 {"_read_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
367 {"__read_lock_bh", LOCK
, bottom_half
, NO_ARG
, ret_any
},
368 {"__read_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
369 {"_raw_read_lock_bh", LOCK
, bottom_half
, NO_ARG
, ret_any
},
370 {"_raw_read_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
371 {"write_lock_bh", LOCK
, bottom_half
, NO_ARG
, ret_any
},
372 {"write_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
373 {"_write_lock_bh", LOCK
, bottom_half
, NO_ARG
, ret_any
},
374 {"_write_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
375 {"__write_lock_bh", LOCK
, bottom_half
, NO_ARG
, ret_any
},
376 {"__write_unlock_bh", UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
377 {"_raw_write_lock_bh", LOCK
, bottom_half
, NO_ARG
, ret_any
},
378 {"_raw_write_unlock_bh",UNLOCK
, bottom_half
, NO_ARG
, ret_any
},
379 {"spin_trylock_bh", LOCK
, bottom_half
, NO_ARG
, ret_one
},
380 {"_spin_trylock_bh", LOCK
, bottom_half
, NO_ARG
, ret_one
},
381 {"__spin_trylock_bh", LOCK
, bottom_half
, NO_ARG
, ret_one
},
383 {"ffs_mutex_lock", LOCK
, mutex
, 0, ret_zero
},
385 {"clk_prepare_lock", LOCK
, prepare_lock
, NO_ARG
, ret_any
},
386 {"clk_prepare_unlock", UNLOCK
, prepare_lock
, NO_ARG
, ret_any
},
387 {"clk_enable_lock", LOCK
, enable_lock
, -1, ret_any
},
388 {"clk_enable_unlock", UNLOCK
, enable_lock
, 0, ret_any
},
390 {"dma_resv_lock", LOCK
, mutex
, 0, ret_zero
},
391 {"dma_resv_trylock", LOCK
, mutex
, 0, ret_one
},
392 {"dma_resv_lock_interruptible", LOCK
, mutex
, 0, ret_zero
},
393 {"dma_resv_unlock", UNLOCK
, mutex
, 0, ret_any
},
395 {"modeset_lock", LOCK
, mutex
, 0, ret_zero
},
396 {"drm_ modeset_lock", LOCK
, mutex
, 0, ret_zero
},
397 {"drm_modeset_lock_single_interruptible", LOCK
, mutex
, 0, ret_zero
},
398 {"modeset_unlock", UNLOCK
, mutex
, 0, ret_any
},
400 {"reiserfs_write_lock_nested", LOCK
, mutex
, 0, ret_any
},
401 {"reiserfs_write_unlock_nested", UNLOCK
, mutex
, 0, ret_any
},
403 {"rw_lock", LOCK
, write_lock
, 1, ret_any
},
404 {"rw_unlock", UNLOCK
, write_lock
, 1, ret_any
},
406 {"sem_lock", LOCK
, mutex
, 0, ret_any
},
407 {"sem_unlock", UNLOCK
, mutex
, 0, ret_any
},
418 static struct macro_info macro_table
[] = {
419 {"genpd_lock", LOCK
, 0},
420 {"genpd_lock_nested", LOCK
, 0},
421 {"genpd_lock_interruptible", LOCK
, 0},
422 {"genpd_unlock", UNLOCK
, 0},
425 static const char *false_positives
[][2] = {
426 {"fs/jffs2/", "->alloc_sem"},
427 {"fs/xfs/", "->b_sema"},
428 {"mm/", "pvmw->ptl"},
431 static struct stree
*start_states
;
433 static struct tracker_list
*locks
;
435 static void reset(struct sm_state
*sm
, struct expression
*mod_expr
)
437 set_state(my_id
, sm
->name
, sm
->sym
, &start_state
);
440 static struct expression
*remove_spinlock_check(struct expression
*expr
)
442 if (expr
->type
!= EXPR_CALL
)
444 if (expr
->fn
->type
!= EXPR_SYMBOL
)
446 if (strcmp(expr
->fn
->symbol_name
->name
, "spinlock_check"))
448 expr
= get_argument_from_call_expr(expr
->args
, 0);
452 static struct expression
*filter_kernel_args(struct expression
*arg
)
454 if (arg
->type
== EXPR_PREOP
&& arg
->op
== '&')
455 return strip_expr(arg
->unop
);
456 if (!is_pointer(arg
))
458 return deref_expression(strip_expr(arg
));
461 static char *lock_to_name_sym(struct expression
*expr
, struct symbol
**sym
)
463 expr
= remove_spinlock_check(expr
);
464 expr
= filter_kernel_args(expr
);
465 return expr_to_str_sym(expr
, sym
);
468 static char *get_full_name(struct expression
*expr
, int index
, struct symbol
**sym
)
470 struct lock_info
*lock
= &lock_table
[index
];
471 struct expression
*arg
;
474 if (lock
->arg
== RETURN_VAL
) {
475 return expr_to_var_sym(strip_expr(expr
->left
), sym
);
476 } else if (lock
->arg
== NO_ARG
) {
477 return alloc_string(get_lock_name(lock
->type
));
479 arg
= get_argument_from_call_expr(expr
->args
, lock
->arg
);
482 return lock_to_name_sym(arg
, sym
);
486 static struct smatch_state
*unmatched_state(struct sm_state
*sm
)
491 static void pre_merge_hook(struct sm_state
*cur
, struct sm_state
*other
)
493 if (is_impossible_path())
494 set_state(my_id
, cur
->name
, cur
->sym
, &impossible
);
497 static struct smatch_state
*merge_func(struct smatch_state
*s1
, struct smatch_state
*s2
)
499 if (s1
== &impossible
)
501 if (s2
== &impossible
)
506 static struct smatch_state
*action_to_state(enum action lock_unlock
)
508 switch (lock_unlock
) {
519 static struct sm_state
*get_best_match(const char *key
, enum action lock_unlock
)
522 struct sm_state
*match
;
524 int start_pos
, state_len
, key_len
, chunks
, i
;
526 if (strncmp(key
, "$->", 3) == 0)
529 key_len
= strlen(key
);
531 for (i
= key_len
- 1; i
> 0; i
--) {
532 if (key
[i
] == '>' || key
[i
] == '.')
536 key_len
= strlen(key
);
541 FOR_EACH_MY_SM(my_id
, __get_cur_stree(), sm
) {
542 if (((lock_unlock
== UNLOCK
|| lock_unlock
== RESTORE
) &&
543 sm
->state
!= &locked
) ||
544 (lock_unlock
== LOCK
&& sm
->state
!= &unlocked
))
546 state_len
= strlen(sm
->name
);
547 if (state_len
< key_len
)
549 start_pos
= state_len
- key_len
;
550 if ((start_pos
== 0 || !isalnum(sm
->name
[start_pos
- 1])) &&
551 strcmp(sm
->name
+ start_pos
, key
) == 0) {
555 } END_FOR_EACH_SM(sm
);
562 static void use_best_match(char *key
, enum action lock_unlock
)
564 struct sm_state
*match
;
566 match
= get_best_match(key
, lock_unlock
);
568 set_state(my_id
, match
->name
, match
->sym
, action_to_state(lock_unlock
));
570 set_state(my_id
, key
, NULL
, action_to_state(lock_unlock
));
573 static void set_start_state(const char *name
, struct symbol
*sym
, struct smatch_state
*start
)
575 struct smatch_state
*orig
;
577 orig
= get_state_stree(start_states
, my_id
, name
, sym
);
579 set_state_stree(&start_states
, my_id
, name
, sym
, start
);
580 else if (orig
!= start
)
581 set_state_stree(&start_states
, my_id
, name
, sym
, &undefined
);
584 static bool common_false_positive(const char *name
)
586 const char *path
, *lname
;
587 int i
, len_total
, len_path
, len_name
, skip
;
592 len_total
= strlen(name
);
593 for (i
= 0; i
< ARRAY_SIZE(false_positives
); i
++) {
594 path
= false_positives
[i
][0];
595 lname
= false_positives
[i
][1];
597 len_path
= strlen(path
);
598 len_name
= strlen(lname
);
600 if (len_name
> len_total
)
602 skip
= len_total
- len_name
;
604 if (strncmp(get_filename(), path
, len_path
) == 0 &&
605 strcmp(name
+ skip
, lname
) == 0)
612 static void warn_on_double(struct sm_state
*sm
, struct smatch_state
*state
)
614 struct sm_state
*tmp
;
619 FOR_EACH_PTR(sm
->possible
, tmp
) {
620 if (tmp
->state
== state
)
622 } END_FOR_EACH_PTR(tmp
);
626 if (strcmp(sm
->name
, "bottom_half") == 0)
628 if (common_false_positive(sm
->name
))
630 sm_msg("error: double %s '%s' (orig line %u)",
631 state
->name
, sm
->name
, tmp
->line
);
634 static bool handle_macro_lock_unlock(void)
636 struct expression
*expr
, *arg
;
637 struct macro_info
*info
;
645 expr
= last_ptr_list((struct ptr_list
*)big_expression_stack
);
646 while (expr
&& expr
->type
== EXPR_ASSIGNMENT
)
647 expr
= strip_expr(expr
->right
);
648 if (!expr
|| expr
->type
!= EXPR_CALL
)
651 macro
= get_macro_name(expr
->pos
);
655 for (i
= 0; i
< ARRAY_SIZE(macro_table
); i
++) {
656 info
= ¯o_table
[i
];
658 if (strcmp(macro
, info
->macro
) != 0)
660 arg
= get_argument_from_call_expr(expr
->args
, info
->param
);
661 name
= expr_to_str_sym(arg
, &sym
);
664 sm
= get_sm_state(my_id
, name
, sym
);
666 if (info
->action
== LOCK
) {
668 set_start_state(name
, sym
, &unlocked
);
669 if (sm
&& sm
->line
!= expr
->pos
.line
)
670 warn_on_double(sm
, &locked
);
671 set_state(my_id
, name
, sym
, &locked
);
674 set_start_state(name
, sym
, &locked
);
675 if (sm
&& sm
->line
!= expr
->pos
.line
)
676 warn_on_double(sm
, &unlocked
);
677 set_state(my_id
, name
, sym
, &unlocked
);
687 static void do_lock(const char *name
, struct symbol
*sym
, struct lock_info
*info
)
691 if (handle_macro_lock_unlock())
694 add_tracker(&locks
, my_id
, name
, sym
);
696 sm
= get_sm_state(my_id
, name
, sym
);
698 set_start_state(name
, sym
, &unlocked
);
699 warn_on_double(sm
, &locked
);
700 set_state(my_id
, name
, sym
, &locked
);
703 static void do_lock_failed(const char *name
, struct symbol
*sym
)
705 add_tracker(&locks
, my_id
, name
, sym
);
706 set_state(my_id
, name
, sym
, &unlocked
);
709 static void do_unlock(const char *name
, struct symbol
*sym
, struct lock_info
*info
)
713 if (__path_is_null())
716 if (handle_macro_lock_unlock())
719 add_tracker(&locks
, my_id
, name
, sym
);
720 sm
= get_sm_state(my_id
, name
, sym
);
722 sm
= get_best_match(name
, UNLOCK
);
729 set_start_state(name
, sym
, &locked
);
730 warn_on_double(sm
, &unlocked
);
731 set_state(my_id
, name
, sym
, &unlocked
);
734 static void do_restore(const char *name
, struct symbol
*sym
, struct lock_info
*info
)
736 if (__path_is_null())
739 if (!get_state(my_id
, name
, sym
))
740 set_start_state(name
, sym
, &locked
);
742 add_tracker(&locks
, my_id
, name
, sym
);
743 set_state(my_id
, name
, sym
, &restore
);
746 static void match_lock_held(const char *fn
, struct expression
*call_expr
,
747 struct expression
*assign_expr
, void *_index
)
749 int index
= PTR_INT(_index
);
750 struct lock_info
*lock
= &lock_table
[index
];
754 if (lock
->arg
== NO_ARG
) {
755 lock_name
= get_full_name(NULL
, index
, &sym
);
756 } else if (lock
->arg
== RETURN_VAL
) {
759 lock_name
= get_full_name(assign_expr
, index
, &sym
);
761 lock_name
= get_full_name(call_expr
, index
, &sym
);
765 do_lock(lock_name
, sym
, lock
);
766 free_string(lock_name
);
769 static void match_lock_failed(const char *fn
, struct expression
*call_expr
,
770 struct expression
*assign_expr
, void *_index
)
772 int index
= PTR_INT(_index
);
773 struct lock_info
*lock
= &lock_table
[index
];
777 if (lock
->arg
== NO_ARG
) {
778 lock_name
= get_full_name(NULL
, index
, &sym
);
779 } else if (lock
->arg
== RETURN_VAL
) {
782 lock_name
= get_full_name(assign_expr
, index
, &sym
);
784 lock_name
= get_full_name(call_expr
, index
, &sym
);
788 do_lock_failed(lock_name
, sym
);
789 free_string(lock_name
);
792 static void match_returns_locked(const char *fn
, struct expression
*expr
,
795 int index
= PTR_INT(_index
);
796 struct lock_info
*lock
= &lock_table
[index
];
800 if (lock
->arg
!= RETURN_VAL
)
802 full_name
= get_full_name(expr
, index
, &sym
);
805 do_lock(full_name
, sym
, lock
);
808 static void match_lock_unlock(const char *fn
, struct expression
*expr
, void *_index
)
810 int index
= PTR_INT(_index
);
811 struct lock_info
*lock
= &lock_table
[index
];
815 full_name
= get_full_name(expr
, index
, &sym
);
818 switch (lock
->action
) {
820 do_lock(full_name
, sym
, lock
);
823 do_unlock(full_name
, sym
, lock
);
826 do_restore(full_name
, sym
, lock
);
829 free_string(full_name
);
832 static struct smatch_state
*get_start_state(struct sm_state
*sm
)
834 struct smatch_state
*orig
;
836 orig
= get_state_stree(start_states
, my_id
, sm
->name
, sm
->sym
);
842 static int get_db_type(struct sm_state
*sm
)
844 if (sm
->state
== get_start_state(sm
)) {
845 if (sm
->state
== &locked
)
847 if (sm
->state
== &unlocked
)
848 return KNOWN_UNLOCKED
;
851 if (sm
->state
== &locked
)
853 if (sm
->state
== &unlocked
)
855 if (sm
->state
== &restore
)
856 return LOCK_RESTORED
;
860 static void match_return_info(int return_id
, char *return_ranges
, struct expression
*expr
)
863 const char *param_name
;
866 FOR_EACH_MY_SM(my_id
, __get_cur_stree(), sm
) {
867 if (sm
->state
!= &locked
&&
868 sm
->state
!= &unlocked
&&
869 sm
->state
!= &restore
)
872 param
= get_param_key_from_sm(sm
, expr
, ¶m_name
);
873 sql_insert_return_states(return_id
, return_ranges
,
875 param
, param_name
, "");
876 } END_FOR_EACH_SM(sm
);
880 ERR_PTR
, VALID_PTR
, NEGATIVE
, ZERO
, POSITIVE
, NUM_BUCKETS
,
883 static bool is_EINTR(struct range_list
*rl
)
887 if (!rl_to_sval(rl
, &sval
))
889 return sval
.value
== -4;
892 static int success_fail_positive(struct range_list
*rl
)
894 /* void returns are the same as success (zero in the kernel) */
898 if (rl_type(rl
)->type
!= SYM_PTR
&& sval_is_negative(rl_min(rl
)))
901 if (rl_min(rl
).value
== 0 && rl_max(rl
).value
== 0)
904 if (is_err_ptr(rl_min(rl
)) &&
905 is_err_ptr(rl_max(rl
)))
909 * Trying to match ERR_PTR(ret) but without the expression struct.
912 if (type_bits(&long_ctype
) == 64 &&
913 rl_type(rl
)->type
== SYM_PTR
&&
914 rl_min(rl
).value
== INT_MIN
)
920 static bool sym_in_lock_table(struct symbol
*sym
)
924 if (!sym
|| !sym
->ident
)
927 for (i
= 0; lock_table
[i
].function
!= NULL
; i
++) {
928 if (strcmp(lock_table
[i
].function
, sym
->ident
->name
) == 0)
934 static bool func_in_lock_table(struct expression
*expr
)
936 if (expr
->type
!= EXPR_SYMBOL
)
938 return sym_in_lock_table(expr
->symbol
);
941 static void check_lock(char *name
, struct symbol
*sym
)
943 struct range_list
*locked_lines
= NULL
;
944 struct range_list
*unlocked_lines
= NULL
;
945 int locked_buckets
[NUM_BUCKETS
] = {};
946 int unlocked_buckets
[NUM_BUCKETS
] = {};
947 struct stree
*stree
, *orig
;
948 struct sm_state
*return_sm
;
950 sval_t line
= sval_type_val(&int_ctype
, 0);
954 if (sym_in_lock_table(cur_func_sym
))
957 FOR_EACH_PTR(get_all_return_strees(), stree
) {
958 orig
= __swap_cur_stree(stree
);
960 if (is_impossible_path())
963 return_sm
= get_sm_state(RETURN_ID
, "return_ranges", NULL
);
966 line
.value
= return_sm
->line
;
968 sm
= get_sm_state(my_id
, name
, sym
);
972 if (parent_is_gone_var_sym(sm
->name
, sm
->sym
))
975 if (sm
->state
!= &locked
&&
976 sm
->state
!= &unlocked
&&
977 sm
->state
!= &restore
)
980 if ((sm
->state
== &unlocked
|| sm
->state
== &restore
) &&
981 is_EINTR(estate_rl(return_sm
->state
)))
984 bucket
= success_fail_positive(estate_rl(return_sm
->state
));
985 if (sm
->state
== &locked
) {
986 add_range(&locked_lines
, line
, line
);
987 locked_buckets
[bucket
] = true;
989 if (sm
->state
== &unlocked
|| sm
->state
== &restore
) {
990 add_range(&unlocked_lines
, line
, line
);
991 unlocked_buckets
[bucket
] = true;
994 __swap_cur_stree(orig
);
995 } END_FOR_EACH_PTR(stree
);
998 if (!locked_lines
|| !unlocked_lines
)
1001 for (i
= 0; i
< NUM_BUCKETS
; i
++) {
1002 if (locked_buckets
[i
] && unlocked_buckets
[i
])
1005 if (locked_buckets
[NEGATIVE
] &&
1006 (unlocked_buckets
[ZERO
] || unlocked_buckets
[POSITIVE
]))
1009 if (locked_buckets
[ERR_PTR
])
1015 sm_msg("warn: inconsistent returns '%s'.", name
);
1016 sm_printf(" Locked on : %s\n", show_rl(locked_lines
));
1017 sm_printf(" Unlocked on: %s\n", show_rl(unlocked_lines
));
1020 static void match_func_end(struct symbol
*sym
)
1022 struct tracker
*tracker
;
1024 FOR_EACH_PTR(locks
, tracker
) {
1025 check_lock(tracker
->name
, tracker
->sym
);
1026 } END_FOR_EACH_PTR(tracker
);
1029 static void register_lock(int index
)
1031 struct lock_info
*lock
= &lock_table
[index
];
1032 void *idx
= INT_PTR(index
);
1034 if (lock
->return_type
== ret_one
) {
1035 return_implies_state(lock
->function
, 1, 1, &match_lock_held
, idx
);
1036 return_implies_state(lock
->function
, 0, 0, &match_lock_failed
, idx
);
1037 } else if (lock
->return_type
== ret_any
&& lock
->arg
== RETURN_VAL
) {
1038 add_function_assign_hook(lock
->function
, &match_returns_locked
, idx
);
1039 } else if (lock
->return_type
== ret_any
) {
1040 add_function_hook(lock
->function
, &match_lock_unlock
, idx
);
1041 } else if (lock
->return_type
== ret_zero
) {
1042 return_implies_state(lock
->function
, 0, 0, &match_lock_held
, idx
);
1043 return_implies_state(lock
->function
, -4095, -1, &match_lock_failed
, idx
);
1044 } else if (lock
->return_type
== ret_valid_ptr
) {
1045 return_implies_state_sval(lock
->function
, valid_ptr_min_sval
, valid_ptr_max_sval
, &match_lock_held
, idx
);
1049 static void load_table(struct lock_info
*lock_table
)
1053 for (i
= 0; lock_table
[i
].function
!= NULL
; i
++) {
1054 if (lock_table
[i
].action
== LOCK
)
1057 add_function_hook(lock_table
[i
].function
, &match_lock_unlock
, INT_PTR(i
));
1061 static void db_param_locked_unlocked(struct expression
*expr
, int param
, char *key
, char *value
, enum action lock_unlock
)
1063 struct expression
*call
, *arg
;
1068 while (call
->type
== EXPR_ASSIGNMENT
)
1069 call
= strip_expr(call
->right
);
1070 if (call
->type
!= EXPR_CALL
)
1073 if (func_in_lock_table(call
->fn
))
1077 use_best_match(key
, lock_unlock
);
1082 if (expr
->type
!= EXPR_ASSIGNMENT
)
1084 name
= get_variable_from_key(expr
->left
, key
, &sym
);
1086 arg
= get_argument_from_call_expr(call
->args
, param
);
1090 name
= get_variable_from_key(arg
, key
, &sym
);
1095 if (lock_unlock
== LOCK
)
1096 do_lock(name
, sym
, NULL
);
1097 else if (lock_unlock
== UNLOCK
)
1098 do_unlock(name
, sym
, NULL
);
1099 else if (lock_unlock
== RESTORE
)
1100 do_restore(name
, sym
, NULL
);
1106 static void db_param_locked(struct expression
*expr
, int param
, char *key
, char *value
)
1108 db_param_locked_unlocked(expr
, param
, key
, value
, LOCK
);
1111 static void db_param_unlocked(struct expression
*expr
, int param
, char *key
, char *value
)
1113 db_param_locked_unlocked(expr
, param
, key
, value
, UNLOCK
);
1116 static void db_param_restore(struct expression
*expr
, int param
, char *key
, char *value
)
1118 db_param_locked_unlocked(expr
, param
, key
, value
, RESTORE
);
1121 static int get_caller_param_lock_name(struct expression
*call
, struct sm_state
*sm
, const char **name
)
1123 struct expression
*arg
;
1128 FOR_EACH_PTR(call
->args
, arg
) {
1129 arg_name
= sm_to_arg_name(arg
, sm
);
1135 } END_FOR_EACH_PTR(arg
);
1141 static void match_call_info(struct expression
*expr
)
1143 struct sm_state
*sm
;
1144 const char *param_name
;
1148 FOR_EACH_MY_SM(my_id
, __get_cur_stree(), sm
) {
1149 param
= get_caller_param_lock_name(expr
, sm
, ¶m_name
);
1150 if (sm
->state
== &locked
)
1151 locked_type
= LOCKED
;
1152 else if (sm
->state
== &half_locked
||
1153 slist_has_state(sm
->possible
, &locked
))
1154 locked_type
= HALF_LOCKED
;
1157 sql_insert_caller_info(expr
, locked_type
, param
, param_name
, "xxx type");
1159 } END_FOR_EACH_SM(sm
);
1162 static void match_save_states(struct expression
*expr
)
1164 push_stree(&saved_stack
, start_states
);
1165 start_states
= NULL
;
1168 static void match_restore_states(struct expression
*expr
)
1170 start_states
= pop_stree(&saved_stack
);
1173 static void match_after_func(struct symbol
*sym
)
1175 free_stree(&start_states
);
1178 static void match_dma_resv_lock_NULL(const char *fn
, struct expression
*call_expr
,
1179 struct expression
*assign_expr
, void *_index
)
1181 struct expression
*lock
, *ctx
;
1185 lock
= get_argument_from_call_expr(call_expr
->args
, 0);
1186 ctx
= get_argument_from_call_expr(call_expr
->args
, 1);
1187 if (!expr_is_zero(ctx
))
1190 lock_name
= lock_to_name_sym(lock
, &sym
);
1191 if (!lock_name
|| !sym
)
1193 do_lock(lock_name
, sym
, NULL
);
1195 free_string(lock_name
);
1198 /* print_held_locks() is used in check_call_tree.c */
1199 void print_held_locks(void)
1201 struct stree
*stree
;
1202 struct sm_state
*sm
;
1205 stree
= __get_cur_stree();
1206 FOR_EACH_MY_SM(my_id
, stree
, sm
) {
1207 if (sm
->state
!= &locked
)
1211 sm_printf("'%s'", sm
->name
);
1212 } END_FOR_EACH_SM(sm
);
1215 static bool is_smp_config(void)
1219 id
= built_in_ident("CONFIG_SMP");
1220 return !!lookup_symbol(id
, NS_MACRO
);
1223 void check_locking(int id
)
1227 if (option_project
!= PROJ_KERNEL
)
1230 if (!is_smp_config())
1233 load_table(lock_table
);
1235 set_dynamic_states(my_id
);
1236 add_unmatched_state_hook(my_id
, &unmatched_state
);
1237 add_pre_merge_hook(my_id
, &pre_merge_hook
);
1238 add_merge_hook(my_id
, &merge_func
);
1239 add_modification_hook(my_id
, &reset
);
1241 add_hook(&match_func_end
, END_FUNC_HOOK
);
1243 add_hook(&match_after_func
, AFTER_FUNC_HOOK
);
1244 add_hook(&match_save_states
, INLINE_FN_START
);
1245 add_hook(&match_restore_states
, INLINE_FN_END
);
1247 add_hook(&match_call_info
, FUNCTION_CALL_HOOK
);
1249 add_split_return_callback(match_return_info
);
1250 select_return_states_hook(LOCKED
, &db_param_locked
);
1251 select_return_states_hook(UNLOCKED
, &db_param_unlocked
);
1252 select_return_states_hook(LOCK_RESTORED
, &db_param_restore
);
1254 return_implies_state("dma_resv_lock", -4095, -1, &match_dma_resv_lock_NULL
, 0);