1// Check if refcount_t type and API should be used
2// instead of atomic_t type when dealing with refcounters
3//
4// Copyright (c) 2016-2017, Elena Reshetova, Intel Corporation
5//
6// Confidence: Moderate
7// URL: http://coccinelle.lip6.fr/
8// Options: --include-headers --very-quiet
9
10virtual report
11
12@r1 exists@
13identifier a, x;
14position p1, p2;
15identifier fname =~ ".*free.*";
16identifier fname2 =~ ".*destroy.*";
17identifier fname3 =~ ".*del.*";
18identifier fname4 =~ ".*queue_work.*";
19identifier fname5 =~ ".*schedule_work.*";
20identifier fname6 =~ ".*call_rcu.*";
21
22@@
23
24(
25 atomic_dec_and_test@p1(&(a)->x)
26|
27 atomic_dec_and_lock@p1(&(a)->x, ...)
28|
29 atomic_long_dec_and_lock@p1(&(a)->x, ...)
30|
31 atomic_long_dec_and_test@p1(&(a)->x)
32|
33 atomic64_dec_and_test@p1(&(a)->x)
34|
35 local_dec_and_test@p1(&(a)->x)
36)
37...
38(
39 fname@p2(a, ...);
40|
41 fname2@p2(...);
42|
43 fname3@p2(...);
44|
45 fname4@p2(...);
46|
47 fname5@p2(...);
48|
49 fname6@p2(...);
50)
51
52
53@script:python depends on report@
54p1 << r1.p1;
55p2 << r1.p2;
56@@
57msg = "atomic_dec_and_test variation before object free at line %s."
58coccilib.report.print_report(p1[0], msg % (p2[0].line))
59
60@r4 exists@
61identifier a, x, y;
62position p1, p2;
63identifier fname =~ ".*free.*";
64
65@@
66
67(
68 atomic_dec_and_test@p1(&(a)->x)
69|
70 atomic_dec_and_lock@p1(&(a)->x, ...)
71|
72 atomic_long_dec_and_lock@p1(&(a)->x, ...)
73|
74 atomic_long_dec_and_test@p1(&(a)->x)
75|
76 atomic64_dec_and_test@p1(&(a)->x)
77|
78 local_dec_and_test@p1(&(a)->x)
79)
80...
81y=a
82...
83fname@p2(y, ...);
84
85
86@script:python depends on report@
87p1 << r4.p1;
88p2 << r4.p2;
89@@
90msg = "atomic_dec_and_test variation before object free at line %s."
91coccilib.report.print_report(p1[0], msg % (p2[0].line))
92
93@r2 exists@
94identifier a, x;
95position p1;
96@@
97
98(
99atomic_add_unless(&(a)->x,-1,1)@p1
100|
101atomic_long_add_unless(&(a)->x,-1,1)@p1
102|
103atomic64_add_unless(&(a)->x,-1,1)@p1
104)
105
106@script:python depends on report@
107p1 << r2.p1;
108@@
109msg = "atomic_add_unless"
110coccilib.report.print_report(p1[0], msg)
111
112@r3 exists@
113identifier x;
114position p1;
115@@
116
117(
118x = atomic_add_return@p1(-1, ...);
119|
120x = atomic_long_add_return@p1(-1, ...);
121|
122x = atomic64_add_return@p1(-1, ...);
123)
124
125@script:python depends on report@
126p1 << r3.p1;
127@@
128msg = "x = atomic_add_return(-1, ...)"
129coccilib.report.print_report(p1[0], msg)
130