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