Lines Matching +full:i +full:- +full:leak +full:- +full:current
1 /* SPDX-License-Identifier: GPL-2.0 */
13 * counter and causing 'spurious' use-after-free issues. In order to avoid the
23 * +--------------------------------+----------------+----------------+
24 * <---------- bad value! ---------->
44 * With the current PID limit, if no batched refcounting operations are used and
50 * (UINT_MAX+1-REFCOUNT_SATURATED) / PID_MAX_LIMIT =
55 * given the precise timing details involved with the round-robin scheduling of
82 * because the 1->0 transition indicates no concurrency.
119 * refcount_set - set a refcount's value
125 atomic_set(&r->refs, n); in refcount_set()
129 * refcount_read - get a refcount's value
136 return atomic_read(&r->refs); in refcount_read()
139 static inline __must_check bool __refcount_add_not_zero(int i, refcount_t *r, int *oldp) in __refcount_add_not_zero() argument
146 } while (!atomic_try_cmpxchg_relaxed(&r->refs, &old, old + i)); in __refcount_add_not_zero()
151 if (unlikely(old < 0 || old + i < 0)) in __refcount_add_not_zero()
158 * refcount_add_not_zero - add a value to a refcount unless it is 0
159 * @i: the value to add to the refcount
175 static inline __must_check bool refcount_add_not_zero(int i, refcount_t *r) in refcount_add_not_zero() argument
177 return __refcount_add_not_zero(i, r, NULL); in refcount_add_not_zero()
180 static inline void __refcount_add(int i, refcount_t *r, int *oldp) in __refcount_add() argument
182 int old = atomic_fetch_add_relaxed(i, &r->refs); in __refcount_add()
189 else if (unlikely(old < 0 || old + i < 0)) in __refcount_add()
194 * refcount_add - add a value to a refcount
195 * @i: the value to add to the refcount
209 static inline void refcount_add(int i, refcount_t *r) in refcount_add() argument
211 __refcount_add(i, r, NULL); in refcount_add()
220 * refcount_inc_not_zero - increment a refcount unless it is 0
243 * refcount_inc - increment a refcount
251 * Will WARN if the refcount is 0, as this represents a possible use-after-free
259 static inline __must_check bool __refcount_sub_and_test(int i, refcount_t *r, int *oldp) in __refcount_sub_and_test() argument
261 int old = atomic_fetch_sub_release(i, &r->refs); in __refcount_sub_and_test()
266 if (old == i) { in __refcount_sub_and_test()
271 if (unlikely(old < 0 || old - i < 0)) in __refcount_sub_and_test()
278 * refcount_sub_and_test - subtract from a refcount and test if it is 0
279 * @i: amount to subtract from the refcount
283 * ultimately leak on underflow and will fail to decrement when saturated
297 static inline __must_check bool refcount_sub_and_test(int i, refcount_t *r) in refcount_sub_and_test() argument
299 return __refcount_sub_and_test(i, r, NULL); in refcount_sub_and_test()
308 * refcount_dec_and_test - decrement a refcount and test if it is 0
327 int old = atomic_fetch_sub_release(1, &r->refs); in __refcount_dec()
337 * refcount_dec - decrement a refcount