xref: /linux-6.15/include/linux/refcount_types.h (revision f9d6966b)
1*f9d6966bSKent Overstreet /* SPDX-License-Identifier: GPL-2.0 */
2*f9d6966bSKent Overstreet #ifndef _LINUX_REFCOUNT_TYPES_H
3*f9d6966bSKent Overstreet #define _LINUX_REFCOUNT_TYPES_H
4*f9d6966bSKent Overstreet 
5*f9d6966bSKent Overstreet #include <linux/types.h>
6*f9d6966bSKent Overstreet 
7*f9d6966bSKent Overstreet /**
8*f9d6966bSKent Overstreet  * typedef refcount_t - variant of atomic_t specialized for reference counts
9*f9d6966bSKent Overstreet  * @refs: atomic_t counter field
10*f9d6966bSKent Overstreet  *
11*f9d6966bSKent Overstreet  * The counter saturates at REFCOUNT_SATURATED and will not move once
12*f9d6966bSKent Overstreet  * there. This avoids wrapping the counter and causing 'spurious'
13*f9d6966bSKent Overstreet  * use-after-free bugs.
14*f9d6966bSKent Overstreet  */
15*f9d6966bSKent Overstreet typedef struct refcount_struct {
16*f9d6966bSKent Overstreet 	atomic_t refs;
17*f9d6966bSKent Overstreet } refcount_t;
18*f9d6966bSKent Overstreet 
19*f9d6966bSKent Overstreet #endif /* _LINUX_REFCOUNT_TYPES_H */
20