Lines 62-74
Link Here
|
62 |
|
62 |
|
63 |
return true; |
63 |
return true; |
64 |
} |
64 |
} |
65 |
EXPORT_SYMBOL_GPL(refcount_add_not_zero); |
65 |
EXPORT_SYMBOL(refcount_add_not_zero); |
66 |
|
66 |
|
67 |
void refcount_add(unsigned int i, refcount_t *r) |
67 |
void refcount_add(unsigned int i, refcount_t *r) |
68 |
{ |
68 |
{ |
69 |
WARN_ONCE(!refcount_add_not_zero(i, r), "refcount_t: addition on 0; use-after-free.\n"); |
69 |
WARN_ONCE(!refcount_add_not_zero(i, r), "refcount_t: addition on 0; use-after-free.\n"); |
70 |
} |
70 |
} |
71 |
EXPORT_SYMBOL_GPL(refcount_add); |
71 |
EXPORT_SYMBOL(refcount_add); |
72 |
|
72 |
|
73 |
/* |
73 |
/* |
74 |
* Similar to atomic_inc_not_zero(), will saturate at UINT_MAX and WARN. |
74 |
* Similar to atomic_inc_not_zero(), will saturate at UINT_MAX and WARN. |
Lines 101-107
Link Here
|
101 |
|
101 |
|
102 |
return true; |
102 |
return true; |
103 |
} |
103 |
} |
104 |
EXPORT_SYMBOL_GPL(refcount_inc_not_zero); |
104 |
EXPORT_SYMBOL(refcount_inc_not_zero); |
105 |
|
105 |
|
106 |
/* |
106 |
/* |
107 |
* Similar to atomic_inc(), will saturate at UINT_MAX and WARN. |
107 |
* Similar to atomic_inc(), will saturate at UINT_MAX and WARN. |
Lines 113-119
Link Here
|
113 |
{ |
113 |
{ |
114 |
WARN_ONCE(!refcount_inc_not_zero(r), "refcount_t: increment on 0; use-after-free.\n"); |
114 |
WARN_ONCE(!refcount_inc_not_zero(r), "refcount_t: increment on 0; use-after-free.\n"); |
115 |
} |
115 |
} |
116 |
EXPORT_SYMBOL_GPL(refcount_inc); |
116 |
EXPORT_SYMBOL(refcount_inc); |
117 |
|
117 |
|
118 |
bool refcount_sub_and_test(unsigned int i, refcount_t *r) |
118 |
bool refcount_sub_and_test(unsigned int i, refcount_t *r) |
119 |
{ |
119 |
{ |
Lines 138-144
Link Here
|
138 |
|
138 |
|
139 |
return !new; |
139 |
return !new; |
140 |
} |
140 |
} |
141 |
EXPORT_SYMBOL_GPL(refcount_sub_and_test); |
141 |
EXPORT_SYMBOL(refcount_sub_and_test); |
142 |
|
142 |
|
143 |
/* |
143 |
/* |
144 |
* Similar to atomic_dec_and_test(), it will WARN on underflow and fail to |
144 |
* Similar to atomic_dec_and_test(), it will WARN on underflow and fail to |
Lines 152-158
Link Here
|
152 |
{ |
152 |
{ |
153 |
return refcount_sub_and_test(1, r); |
153 |
return refcount_sub_and_test(1, r); |
154 |
} |
154 |
} |
155 |
EXPORT_SYMBOL_GPL(refcount_dec_and_test); |
155 |
EXPORT_SYMBOL(refcount_dec_and_test); |
156 |
|
156 |
|
157 |
/* |
157 |
/* |
158 |
* Similar to atomic_dec(), it will WARN on underflow and fail to decrement |
158 |
* Similar to atomic_dec(), it will WARN on underflow and fail to decrement |
Lines 166-172
Link Here
|
166 |
{ |
166 |
{ |
167 |
WARN_ONCE(refcount_dec_and_test(r), "refcount_t: decrement hit 0; leaking memory.\n"); |
167 |
WARN_ONCE(refcount_dec_and_test(r), "refcount_t: decrement hit 0; leaking memory.\n"); |
168 |
} |
168 |
} |
169 |
EXPORT_SYMBOL_GPL(refcount_dec); |
169 |
EXPORT_SYMBOL(refcount_dec); |
170 |
|
170 |
|
171 |
/* |
171 |
/* |
172 |
* No atomic_t counterpart, it attempts a 1 -> 0 transition and returns the |
172 |
* No atomic_t counterpart, it attempts a 1 -> 0 transition and returns the |
Lines 183-189
Link Here
|
183 |
{ |
183 |
{ |
184 |
return atomic_cmpxchg_release(&r->refs, 1, 0) == 1; |
184 |
return atomic_cmpxchg_release(&r->refs, 1, 0) == 1; |
185 |
} |
185 |
} |
186 |
EXPORT_SYMBOL_GPL(refcount_dec_if_one); |
186 |
EXPORT_SYMBOL(refcount_dec_if_one); |
187 |
|
187 |
|
188 |
/* |
188 |
/* |
189 |
* No atomic_t counterpart, it decrements unless the value is 1, in which case |
189 |
* No atomic_t counterpart, it decrements unless the value is 1, in which case |
Lines 217-223
Link Here
|
217 |
|
217 |
|
218 |
return true; |
218 |
return true; |
219 |
} |
219 |
} |
220 |
EXPORT_SYMBOL_GPL(refcount_dec_not_one); |
220 |
EXPORT_SYMBOL(refcount_dec_not_one); |
221 |
|
221 |
|
222 |
/* |
222 |
/* |
223 |
* Similar to atomic_dec_and_mutex_lock(), it will WARN on underflow and fail |
223 |
* Similar to atomic_dec_and_mutex_lock(), it will WARN on underflow and fail |
Lines 240-246
Link Here
|
240 |
|
240 |
|
241 |
return true; |
241 |
return true; |
242 |
} |
242 |
} |
243 |
EXPORT_SYMBOL_GPL(refcount_dec_and_mutex_lock); |
243 |
EXPORT_SYMBOL(refcount_dec_and_mutex_lock); |
244 |
|
244 |
|
245 |
/* |
245 |
/* |
246 |
* Similar to atomic_dec_and_lock(), it will WARN on underflow and fail to |
246 |
* Similar to atomic_dec_and_lock(), it will WARN on underflow and fail to |
Lines 263-267
Link Here
|
263 |
|
263 |
|
264 |
return true; |
264 |
return true; |
265 |
} |
265 |
} |
266 |
EXPORT_SYMBOL_GPL(refcount_dec_and_lock); |
266 |
EXPORT_SYMBOL(refcount_dec_and_lock); |