blob: c3ad098f4a5ba27c6fc34ccfe0ec0044f993290b [file] [log] [blame]
Thomas Gleixner7f904d72019-06-04 10:11:38 +02001// SPDX-License-Identifier: GPL-2.0-only
Nicolas Palix54c05622010-08-24 17:39:00 +02002/// Find missing unlocks. This semantic match considers the specific case
3/// where the unlock is missing from an if branch, and there is a lock
4/// before the if and an unlock after the if. False positives are due to
5/// cases where the if branch represents a case where the function is
6/// supposed to exit with the lock held, or where there is some preceding
7/// function call that releases the lock.
8///
9// Confidence: Moderate
Thomas Gleixner7f904d72019-06-04 10:11:38 +020010// Copyright: (C) 2010-2012 Nicolas Palix.
11// Copyright: (C) 2010-2012 Julia Lawall, INRIA/LIP6.
12// Copyright: (C) 2010-2012 Gilles Muller, INRIA/LiP6.
Nicolas Palix54c05622010-08-24 17:39:00 +020013// URL: http://coccinelle.lip6.fr/
14// Comments:
Nicolas Palix93f14462013-06-20 13:10:56 +020015// Options: --no-includes --include-headers
Nicolas Palix54c05622010-08-24 17:39:00 +020016
Julia Lawall29a36d42012-01-14 23:41:54 +010017virtual context
Nicolas Palix54c05622010-08-24 17:39:00 +020018virtual org
19virtual report
20
21@prelocked@
22position p1,p;
23expression E1;
24@@
25
26(
27mutex_lock@p1
28|
29mutex_trylock@p1
30|
31spin_lock@p1
32|
33spin_trylock@p1
34|
35read_lock@p1
36|
37read_trylock@p1
38|
39write_lock@p1
40|
41write_trylock@p1
42|
43read_lock_irq@p1
44|
45write_lock_irq@p1
46|
47read_lock_irqsave@p1
48|
49write_lock_irqsave@p1
50|
51spin_lock_irq@p1
52|
53spin_lock_irqsave@p1
54) (E1@p,...);
55
56@looped@
57position r;
58@@
59
60for(...;...;...) { <+... return@r ...; ...+> }
61
Julia Lawall29a36d42012-01-14 23:41:54 +010062@err exists@
Nicolas Palix54c05622010-08-24 17:39:00 +020063expression E1;
64position prelocked.p;
65position up != prelocked.p1;
66position r!=looped.r;
67identifier lock,unlock;
68@@
69
Julia Lawall29a36d42012-01-14 23:41:54 +010070*lock(E1@p,...);
Julia Lawall32d05722018-05-21 08:58:48 +020071... when != E1
72 when any
Nicolas Palix54c05622010-08-24 17:39:00 +020073if (...) {
74 ... when != E1
Julia Lawall29a36d42012-01-14 23:41:54 +010075* return@r ...;
Nicolas Palix54c05622010-08-24 17:39:00 +020076}
Julia Lawall32d05722018-05-21 08:58:48 +020077... when != E1
78 when any
Julia Lawall29a36d42012-01-14 23:41:54 +010079*unlock@up(E1,...);
Nicolas Palix54c05622010-08-24 17:39:00 +020080
81@script:python depends on org@
82p << prelocked.p1;
83lock << err.lock;
84unlock << err.unlock;
85p2 << err.r;
86@@
87
88cocci.print_main(lock,p)
89cocci.print_secs(unlock,p2)
90
91@script:python depends on report@
92p << prelocked.p1;
93lock << err.lock;
94unlock << err.unlock;
95p2 << err.r;
96@@
97
98msg = "preceding lock on line %s" % (p[0].line)
99coccilib.report.print_report(p2[0],msg)