1 // SPDX-License-Identifier: GPL-2.0-only
2 // Check if refcount_t type and API should be used
3 // instead of atomic_t type when dealing with refcounters
5 // Copyright (c) 2016-2017, Elena Reshetova, Intel Corporation
7 // Confidence: Moderate
8 // URL: http://coccinelle.lip6.fr/
9 // Options: --include-headers --very-quiet
16 identifier fname =~ ".*free.*";
17 identifier fname2 =~ ".*destroy.*";
18 identifier fname3 =~ ".*del.*";
19 identifier fname4 =~ ".*queue_work.*";
20 identifier fname5 =~ ".*schedule_work.*";
21 identifier fname6 =~ ".*call_rcu.*";
26 atomic_dec_and_test@p1(&(a)->x)
28 atomic_dec_and_lock@p1(&(a)->x, ...)
30 atomic_long_dec_and_lock@p1(&(a)->x, ...)
32 atomic_long_dec_and_test@p1(&(a)->x)
34 atomic64_dec_and_test@p1(&(a)->x)
36 local_dec_and_test@p1(&(a)->x)
54 @script:python depends on report@
58 msg = "atomic_dec_and_test variation before object free at line %s."
59 coccilib.report.print_report(p1[0], msg % (p2[0].line))
64 identifier fname =~ ".*free.*";
69 atomic_dec_and_test@p1(&(a)->x)
71 atomic_dec_and_lock@p1(&(a)->x, ...)
73 atomic_long_dec_and_lock@p1(&(a)->x, ...)
75 atomic_long_dec_and_test@p1(&(a)->x)
77 atomic64_dec_and_test@p1(&(a)->x)
79 local_dec_and_test@p1(&(a)->x)
87 @script:python depends on report@
91 msg = "atomic_dec_and_test variation before object free at line %s."
92 coccilib.report.print_report(p1[0], msg % (p2[0].line))
100 atomic_add_unless(&(a)->x,-1,1)@p1
102 atomic_long_add_unless(&(a)->x,-1,1)@p1
104 atomic64_add_unless(&(a)->x,-1,1)@p1
107 @script:python depends on report@
110 msg = "atomic_add_unless"
111 coccilib.report.print_report(p1[0], msg)
119 x = atomic_add_return@p1(-1, ...);
121 x = atomic_long_add_return@p1(-1, ...);
123 x = atomic64_add_return@p1(-1, ...);
126 @script:python depends on report@
129 msg = "x = atomic_add_return(-1, ...)"
130 coccilib.report.print_report(p1[0], msg)