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