Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 // Check if refcount_t type and API should be used
0003 // instead of atomic_t type when dealing with refcounters
0004 //
0005 // Copyright (c) 2016-2017, Elena Reshetova, Intel Corporation
0006 //
0007 // Confidence: Moderate
0008 // URL: https://coccinelle.gitlabpages.inria.fr/website
0009 // Options: --include-headers --very-quiet
0010 
0011 virtual report
0012 
0013 @r1 exists@
0014 identifier a, x;
0015 position p1, p2;
0016 identifier fname =~ ".*free.*";
0017 identifier fname2 =~ ".*destroy.*";
0018 identifier fname3 =~ ".*del.*";
0019 identifier fname4 =~ ".*queue_work.*";
0020 identifier fname5 =~ ".*schedule_work.*";
0021 identifier fname6 =~ ".*call_rcu.*";
0022 
0023 @@
0024 
0025 (
0026  atomic_dec_and_test@p1(&(a)->x)
0027 |
0028  atomic_dec_and_lock@p1(&(a)->x, ...)
0029 |
0030  atomic_long_dec_and_lock@p1(&(a)->x, ...)
0031 |
0032  atomic_long_dec_and_test@p1(&(a)->x)
0033 |
0034  atomic64_dec_and_test@p1(&(a)->x)
0035 |
0036  local_dec_and_test@p1(&(a)->x)
0037 )
0038 ...
0039 (
0040  fname@p2(a, ...);
0041 |
0042  fname2@p2(...);
0043 |
0044  fname3@p2(...);
0045 |
0046  fname4@p2(...);
0047 |
0048  fname5@p2(...);
0049 |
0050  fname6@p2(...);
0051 )
0052 
0053 
0054 @script:python depends on report@
0055 p1 << r1.p1;
0056 p2 << r1.p2;
0057 @@
0058 msg = "atomic_dec_and_test variation before object free at line %s."
0059 coccilib.report.print_report(p1[0], msg % (p2[0].line))
0060 
0061 @r4 exists@
0062 identifier a, x, y;
0063 position p1, p2;
0064 identifier fname =~ ".*free.*";
0065 
0066 @@
0067 
0068 (
0069  atomic_dec_and_test@p1(&(a)->x)
0070 |
0071  atomic_dec_and_lock@p1(&(a)->x, ...)
0072 |
0073  atomic_long_dec_and_lock@p1(&(a)->x, ...)
0074 |
0075  atomic_long_dec_and_test@p1(&(a)->x)
0076 |
0077  atomic64_dec_and_test@p1(&(a)->x)
0078 |
0079  local_dec_and_test@p1(&(a)->x)
0080 )
0081 ...
0082 y=a
0083 ...
0084 fname@p2(y, ...);
0085 
0086 
0087 @script:python depends on report@
0088 p1 << r4.p1;
0089 p2 << r4.p2;
0090 @@
0091 msg = "atomic_dec_and_test variation before object free at line %s."
0092 coccilib.report.print_report(p1[0], msg % (p2[0].line))
0093 
0094 @r2 exists@
0095 identifier a, x;
0096 position p1;
0097 @@
0098 
0099 (
0100 atomic_add_unless(&(a)->x,-1,1)@p1
0101 |
0102 atomic_long_add_unless(&(a)->x,-1,1)@p1
0103 |
0104 atomic64_add_unless(&(a)->x,-1,1)@p1
0105 )
0106 
0107 @script:python depends on report@
0108 p1 << r2.p1;
0109 @@
0110 msg = "atomic_add_unless"
0111 coccilib.report.print_report(p1[0], msg)
0112 
0113 @r3 exists@
0114 identifier x;
0115 position p1;
0116 @@
0117 
0118 (
0119 x = atomic_add_return@p1(-1, ...);
0120 |
0121 x = atomic_long_add_return@p1(-1, ...);
0122 |
0123 x = atomic64_add_return@p1(-1, ...);
0124 )
0125 
0126 @script:python depends on report@
0127 p1 << r3.p1;
0128 @@
0129 msg = "x = atomic_add_return(-1, ...)"
0130 coccilib.report.print_report(p1[0], msg)