5
5
* The interface matches the atomic_t interface (to aid in porting) but only
6
6
* provides the few functions one should use for reference counting.
7
7
*
8
- * It differs in that the counter saturates at UINT_MAX and will not move once
9
- * there. This avoids wrapping the counter and causing 'spurious'
8
+ * It differs in that the counter saturates at REFCOUNT_SATURATED and will not
9
+ * move once there. This avoids wrapping the counter and causing 'spurious'
10
10
* use-after-free issues.
11
11
*
12
12
* Memory ordering rules are slightly relaxed wrt regular atomic_t functions
48
48
* @i: the value to add to the refcount
49
49
* @r: the refcount
50
50
*
51
- * Will saturate at UINT_MAX and WARN.
51
+ * Will saturate at REFCOUNT_SATURATED and WARN.
52
52
*
53
53
* Provides no memory ordering, it is assumed the caller has guaranteed the
54
54
* object memory to be stable (RCU, etc.). It does provide a control dependency
@@ -69,16 +69,17 @@ bool refcount_add_not_zero_checked(unsigned int i, refcount_t *r)
69
69
if (!val )
70
70
return false;
71
71
72
- if (unlikely (val == UINT_MAX ))
72
+ if (unlikely (val == REFCOUNT_SATURATED ))
73
73
return true;
74
74
75
75
new = val + i ;
76
76
if (new < val )
77
- new = UINT_MAX ;
77
+ new = REFCOUNT_SATURATED ;
78
78
79
79
} while (!atomic_try_cmpxchg_relaxed (& r -> refs , & val , new ));
80
80
81
- WARN_ONCE (new == UINT_MAX , "refcount_t: saturated; leaking memory.\n" );
81
+ WARN_ONCE (new == REFCOUNT_SATURATED ,
82
+ "refcount_t: saturated; leaking memory.\n" );
82
83
83
84
return true;
84
85
}
@@ -89,7 +90,7 @@ EXPORT_SYMBOL(refcount_add_not_zero_checked);
89
90
* @i: the value to add to the refcount
90
91
* @r: the refcount
91
92
*
92
- * Similar to atomic_add(), but will saturate at UINT_MAX and WARN.
93
+ * Similar to atomic_add(), but will saturate at REFCOUNT_SATURATED and WARN.
93
94
*
94
95
* Provides no memory ordering, it is assumed the caller has guaranteed the
95
96
* object memory to be stable (RCU, etc.). It does provide a control dependency
@@ -110,7 +111,8 @@ EXPORT_SYMBOL(refcount_add_checked);
110
111
* refcount_inc_not_zero_checked - increment a refcount unless it is 0
111
112
* @r: the refcount to increment
112
113
*
113
- * Similar to atomic_inc_not_zero(), but will saturate at UINT_MAX and WARN.
114
+ * Similar to atomic_inc_not_zero(), but will saturate at REFCOUNT_SATURATED
115
+ * and WARN.
114
116
*
115
117
* Provides no memory ordering, it is assumed the caller has guaranteed the
116
118
* object memory to be stable (RCU, etc.). It does provide a control dependency
@@ -133,7 +135,8 @@ bool refcount_inc_not_zero_checked(refcount_t *r)
133
135
134
136
} while (!atomic_try_cmpxchg_relaxed (& r -> refs , & val , new ));
135
137
136
- WARN_ONCE (new == UINT_MAX , "refcount_t: saturated; leaking memory.\n" );
138
+ WARN_ONCE (new == REFCOUNT_SATURATED ,
139
+ "refcount_t: saturated; leaking memory.\n" );
137
140
138
141
return true;
139
142
}
@@ -143,7 +146,7 @@ EXPORT_SYMBOL(refcount_inc_not_zero_checked);
143
146
* refcount_inc_checked - increment a refcount
144
147
* @r: the refcount to increment
145
148
*
146
- * Similar to atomic_inc(), but will saturate at UINT_MAX and WARN.
149
+ * Similar to atomic_inc(), but will saturate at REFCOUNT_SATURATED and WARN.
147
150
*
148
151
* Provides no memory ordering, it is assumed the caller already has a
149
152
* reference on the object.
@@ -164,7 +167,7 @@ EXPORT_SYMBOL(refcount_inc_checked);
164
167
*
165
168
* Similar to atomic_dec_and_test(), but it will WARN, return false and
166
169
* ultimately leak on underflow and will fail to decrement when saturated
167
- * at UINT_MAX .
170
+ * at REFCOUNT_SATURATED .
168
171
*
169
172
* Provides release memory ordering, such that prior loads and stores are done
170
173
* before, and provides an acquire ordering on success such that free()
@@ -182,7 +185,7 @@ bool refcount_sub_and_test_checked(unsigned int i, refcount_t *r)
182
185
unsigned int new , val = atomic_read (& r -> refs );
183
186
184
187
do {
185
- if (unlikely (val == UINT_MAX ))
188
+ if (unlikely (val == REFCOUNT_SATURATED ))
186
189
return false;
187
190
188
191
new = val - i ;
@@ -207,7 +210,7 @@ EXPORT_SYMBOL(refcount_sub_and_test_checked);
207
210
* @r: the refcount
208
211
*
209
212
* Similar to atomic_dec_and_test(), it will WARN on underflow and fail to
210
- * decrement when saturated at UINT_MAX .
213
+ * decrement when saturated at REFCOUNT_SATURATED .
211
214
*
212
215
* Provides release memory ordering, such that prior loads and stores are done
213
216
* before, and provides an acquire ordering on success such that free()
@@ -226,7 +229,7 @@ EXPORT_SYMBOL(refcount_dec_and_test_checked);
226
229
* @r: the refcount
227
230
*
228
231
* Similar to atomic_dec(), it will WARN on underflow and fail to decrement
229
- * when saturated at UINT_MAX .
232
+ * when saturated at REFCOUNT_SATURATED .
230
233
*
231
234
* Provides release memory ordering, such that prior loads and stores are done
232
235
* before.
@@ -277,7 +280,7 @@ bool refcount_dec_not_one(refcount_t *r)
277
280
unsigned int new , val = atomic_read (& r -> refs );
278
281
279
282
do {
280
- if (unlikely (val == UINT_MAX ))
283
+ if (unlikely (val == REFCOUNT_SATURATED ))
281
284
return true;
282
285
283
286
if (val == 1 )
@@ -302,7 +305,7 @@ EXPORT_SYMBOL(refcount_dec_not_one);
302
305
* @lock: the mutex to be locked
303
306
*
304
307
* Similar to atomic_dec_and_mutex_lock(), it will WARN on underflow and fail
305
- * to decrement when saturated at UINT_MAX .
308
+ * to decrement when saturated at REFCOUNT_SATURATED .
306
309
*
307
310
* Provides release memory ordering, such that prior loads and stores are done
308
311
* before, and provides a control dependency such that free() must come after.
@@ -333,7 +336,7 @@ EXPORT_SYMBOL(refcount_dec_and_mutex_lock);
333
336
* @lock: the spinlock to be locked
334
337
*
335
338
* Similar to atomic_dec_and_lock(), it will WARN on underflow and fail to
336
- * decrement when saturated at UINT_MAX .
339
+ * decrement when saturated at REFCOUNT_SATURATED .
337
340
*
338
341
* Provides release memory ordering, such that prior loads and stores are done
339
342
* before, and provides a control dependency such that free() must come after.
0 commit comments