Linux Audio

Check our new training course

Loading...
v6.2
 1// SPDX-License-Identifier: GPL-2.0-only
 2/// Find double locks.  False positives may occur when some paths cannot
 3/// occur at execution, due to the values of variables, and when there is
 4/// an intervening function call that releases the lock.
 5///
 6// Confidence: Moderate
 7// Copyright: (C) 2010 Nicolas Palix, DIKU.
 8// Copyright: (C) 2010 Julia Lawall, DIKU.
 9// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.
10// URL: https://coccinelle.gitlabpages.inria.fr/website
11// Comments:
12// Options: --no-includes --include-headers
13
14virtual org
15virtual report
16
17@locked@
18position p1;
19expression E1;
20position p;
21@@
22
23(
24mutex_lock@p1
25|
26mutex_trylock@p1
27|
28spin_lock@p1
29|
30spin_trylock@p1
31|
32read_lock@p1
33|
34read_trylock@p1
35|
36write_lock@p1
37|
38write_trylock@p1
39) (E1@p,...);
40
41@balanced@
42position p1 != locked.p1;
43position locked.p;
44identifier lock,unlock;
45expression x <= locked.E1;
46expression E,locked.E1;
47expression E2;
48@@
49
50if (E) {
51 <+... when != E1
52 lock(E1@p,...)
53 ...+>
54}
55... when != E1
56    when != \(x = E2\|&x\)
57    when forall
58if (E) {
59 <+... when != E1
60 unlock@p1(E1,...)
61 ...+>
62}
63
64@r depends on !balanced exists@
65expression x <= locked.E1;
66expression locked.E1;
67expression E2;
68identifier lock;
69position locked.p,p1,p2;
70@@
71
72lock@p1 (E1@p,...);
73... when != E1
74    when != \(x = E2\|&x\)
75lock@p2 (E1,...);
76
77@script:python depends on org@
78p1 << r.p1;
79p2 << r.p2;
80lock << r.lock;
81@@
82
83cocci.print_main(lock,p1)
84cocci.print_secs("second lock",p2)
85
86@script:python depends on report@
87p1 << r.p1;
88p2 << r.p2;
89lock << r.lock;
90@@
91
92msg = "second lock on line %s" % (p2[0].line)
93coccilib.report.print_report(p1[0],msg)
v4.10.11
 
 1/// Find double locks.  False positives may occur when some paths cannot
 2/// occur at execution, due to the values of variables, and when there is
 3/// an intervening function call that releases the lock.
 4///
 5// Confidence: Moderate
 6// Copyright: (C) 2010 Nicolas Palix, DIKU.  GPLv2.
 7// Copyright: (C) 2010 Julia Lawall, DIKU.  GPLv2.
 8// Copyright: (C) 2010 Gilles Muller, INRIA/LiP6.  GPLv2.
 9// URL: http://coccinelle.lip6.fr/
10// Comments:
11// Options: --no-includes --include-headers
12
13virtual org
14virtual report
15
16@locked@
17position p1;
18expression E1;
19position p;
20@@
21
22(
23mutex_lock@p1
24|
25mutex_trylock@p1
26|
27spin_lock@p1
28|
29spin_trylock@p1
30|
31read_lock@p1
32|
33read_trylock@p1
34|
35write_lock@p1
36|
37write_trylock@p1
38) (E1@p,...);
39
40@balanced@
41position p1 != locked.p1;
42position locked.p;
43identifier lock,unlock;
44expression x <= locked.E1;
45expression E,locked.E1;
46expression E2;
47@@
48
49if (E) {
50 <+... when != E1
51 lock(E1@p,...)
52 ...+>
53}
54... when != E1
55    when != \(x = E2\|&x\)
56    when forall
57if (E) {
58 <+... when != E1
59 unlock@p1(E1,...)
60 ...+>
61}
62
63@r depends on !balanced exists@
64expression x <= locked.E1;
65expression locked.E1;
66expression E2;
67identifier lock;
68position locked.p,p1,p2;
69@@
70
71lock@p1 (E1@p,...);
72... when != E1
73    when != \(x = E2\|&x\)
74lock@p2 (E1,...);
75
76@script:python depends on org@
77p1 << r.p1;
78p2 << r.p2;
79lock << r.lock;
80@@
81
82cocci.print_main(lock,p1)
83cocci.print_secs("second lock",p2)
84
85@script:python depends on report@
86p1 << r.p1;
87p2 << r.p2;
88lock << r.lock;
89@@
90
91msg = "second lock on line %s" % (p2[0].line)
92coccilib.report.print_report(p1[0],msg)