43
43
#include <linux/spinlock.h>
44
44
#include <linux/bug.h>
45
45
46
+ #ifdef CONFIG_REFCOUNT_FULL
47
+
46
48
/**
47
- * refcount_add_not_zero_checked - add a value to a refcount unless it is 0
49
+ * refcount_add_not_zero - add a value to a refcount unless it is 0
48
50
* @i: the value to add to the refcount
49
51
* @r: the refcount
50
52
*
61
63
*
62
64
* Return: false if the passed refcount is 0, true otherwise
63
65
*/
64
- bool refcount_add_not_zero_checked (int i , refcount_t * r )
66
+ bool refcount_add_not_zero (int i , refcount_t * r )
65
67
{
66
68
unsigned int new , val = atomic_read (& r -> refs );
67
69
@@ -83,10 +85,10 @@ bool refcount_add_not_zero_checked(int i, refcount_t *r)
83
85
84
86
return true;
85
87
}
86
- EXPORT_SYMBOL (refcount_add_not_zero_checked );
88
+ EXPORT_SYMBOL (refcount_add_not_zero );
87
89
88
90
/**
89
- * refcount_add_checked - add a value to a refcount
91
+ * refcount_add - add a value to a refcount
90
92
* @i: the value to add to the refcount
91
93
* @r: the refcount
92
94
*
@@ -101,14 +103,14 @@ EXPORT_SYMBOL(refcount_add_not_zero_checked);
101
103
* cases, refcount_inc(), or one of its variants, should instead be used to
102
104
* increment a reference count.
103
105
*/
104
- void refcount_add_checked (int i , refcount_t * r )
106
+ void refcount_add (int i , refcount_t * r )
105
107
{
106
- WARN_ONCE (!refcount_add_not_zero_checked (i , r ), "refcount_t: addition on 0; use-after-free.\n" );
108
+ WARN_ONCE (!refcount_add_not_zero (i , r ), "refcount_t: addition on 0; use-after-free.\n" );
107
109
}
108
- EXPORT_SYMBOL (refcount_add_checked );
110
+ EXPORT_SYMBOL (refcount_add );
109
111
110
112
/**
111
- * refcount_inc_not_zero_checked - increment a refcount unless it is 0
113
+ * refcount_inc_not_zero - increment a refcount unless it is 0
112
114
* @r: the refcount to increment
113
115
*
114
116
* Similar to atomic_inc_not_zero(), but will saturate at REFCOUNT_SATURATED
@@ -120,7 +122,7 @@ EXPORT_SYMBOL(refcount_add_checked);
120
122
*
121
123
* Return: true if the increment was successful, false otherwise
122
124
*/
123
- bool refcount_inc_not_zero_checked (refcount_t * r )
125
+ bool refcount_inc_not_zero (refcount_t * r )
124
126
{
125
127
unsigned int new , val = atomic_read (& r -> refs );
126
128
@@ -140,10 +142,10 @@ bool refcount_inc_not_zero_checked(refcount_t *r)
140
142
141
143
return true;
142
144
}
143
- EXPORT_SYMBOL (refcount_inc_not_zero_checked );
145
+ EXPORT_SYMBOL (refcount_inc_not_zero );
144
146
145
147
/**
146
- * refcount_inc_checked - increment a refcount
148
+ * refcount_inc - increment a refcount
147
149
* @r: the refcount to increment
148
150
*
149
151
* Similar to atomic_inc(), but will saturate at REFCOUNT_SATURATED and WARN.
@@ -154,14 +156,14 @@ EXPORT_SYMBOL(refcount_inc_not_zero_checked);
154
156
* Will WARN if the refcount is 0, as this represents a possible use-after-free
155
157
* condition.
156
158
*/
157
- void refcount_inc_checked (refcount_t * r )
159
+ void refcount_inc (refcount_t * r )
158
160
{
159
- WARN_ONCE (!refcount_inc_not_zero_checked (r ), "refcount_t: increment on 0; use-after-free.\n" );
161
+ WARN_ONCE (!refcount_inc_not_zero (r ), "refcount_t: increment on 0; use-after-free.\n" );
160
162
}
161
- EXPORT_SYMBOL (refcount_inc_checked );
163
+ EXPORT_SYMBOL (refcount_inc );
162
164
163
165
/**
164
- * refcount_sub_and_test_checked - subtract from a refcount and test if it is 0
166
+ * refcount_sub_and_test - subtract from a refcount and test if it is 0
165
167
* @i: amount to subtract from the refcount
166
168
* @r: the refcount
167
169
*
@@ -180,7 +182,7 @@ EXPORT_SYMBOL(refcount_inc_checked);
180
182
*
181
183
* Return: true if the resulting refcount is 0, false otherwise
182
184
*/
183
- bool refcount_sub_and_test_checked (int i , refcount_t * r )
185
+ bool refcount_sub_and_test (int i , refcount_t * r )
184
186
{
185
187
unsigned int new , val = atomic_read (& r -> refs );
186
188
@@ -203,10 +205,10 @@ bool refcount_sub_and_test_checked(int i, refcount_t *r)
203
205
return false;
204
206
205
207
}
206
- EXPORT_SYMBOL (refcount_sub_and_test_checked );
208
+ EXPORT_SYMBOL (refcount_sub_and_test );
207
209
208
210
/**
209
- * refcount_dec_and_test_checked - decrement a refcount and test if it is 0
211
+ * refcount_dec_and_test - decrement a refcount and test if it is 0
210
212
* @r: the refcount
211
213
*
212
214
* Similar to atomic_dec_and_test(), it will WARN on underflow and fail to
@@ -218,14 +220,14 @@ EXPORT_SYMBOL(refcount_sub_and_test_checked);
218
220
*
219
221
* Return: true if the resulting refcount is 0, false otherwise
220
222
*/
221
- bool refcount_dec_and_test_checked (refcount_t * r )
223
+ bool refcount_dec_and_test (refcount_t * r )
222
224
{
223
- return refcount_sub_and_test_checked (1 , r );
225
+ return refcount_sub_and_test (1 , r );
224
226
}
225
- EXPORT_SYMBOL (refcount_dec_and_test_checked );
227
+ EXPORT_SYMBOL (refcount_dec_and_test );
226
228
227
229
/**
228
- * refcount_dec_checked - decrement a refcount
230
+ * refcount_dec - decrement a refcount
229
231
* @r: the refcount
230
232
*
231
233
* Similar to atomic_dec(), it will WARN on underflow and fail to decrement
@@ -234,11 +236,13 @@ EXPORT_SYMBOL(refcount_dec_and_test_checked);
234
236
* Provides release memory ordering, such that prior loads and stores are done
235
237
* before.
236
238
*/
237
- void refcount_dec_checked (refcount_t * r )
239
+ void refcount_dec (refcount_t * r )
238
240
{
239
- WARN_ONCE (refcount_dec_and_test_checked (r ), "refcount_t: decrement hit 0; leaking memory.\n" );
241
+ WARN_ONCE (refcount_dec_and_test (r ), "refcount_t: decrement hit 0; leaking memory.\n" );
240
242
}
241
- EXPORT_SYMBOL (refcount_dec_checked );
243
+ EXPORT_SYMBOL (refcount_dec );
244
+
245
+ #endif /* CONFIG_REFCOUNT_FULL */
242
246
243
247
/**
244
248
* refcount_dec_if_one - decrement a refcount if it is 1
0 commit comments