summaryrefslogtreecommitdiff
path: root/include/linux/refcount.h
diff options
context:
space:
mode:
authorSean Paul <seanpaul@chromium.org>2017-06-19 20:39:28 +0300
committerSean Paul <seanpaul@chromium.org>2017-06-19 20:39:28 +0300
commitd4e0045c4ed300781d2d4cbab57d05ed5e665a37 (patch)
tree925bab41d7906329392aa12c8fa7bcc70f64ca46 /include/linux/refcount.h
parent2d7b56378d32b0cf006f8944cbba4046df45dd25 (diff)
parent41f1830f5a7af77cf5c86359aba3cbd706687e52 (diff)
downloadlinux-d4e0045c4ed300781d2d4cbab57d05ed5e665a37.tar.xz
Merge remote-tracking branch 'origin/master' into drm-misc-next-fixes
Backmerge 4.12-rc6 into -next-fixes. -next-fixes will contain find patches for 4.13 merge window
Diffstat (limited to 'include/linux/refcount.h')
-rw-r--r--include/linux/refcount.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/linux/refcount.h b/include/linux/refcount.h
index 0023fee4bbbc..b34aa649d204 100644
--- a/include/linux/refcount.h
+++ b/include/linux/refcount.h
@@ -6,17 +6,36 @@
#include <linux/spinlock.h>
#include <linux/kernel.h>
+/**
+ * refcount_t - variant of atomic_t specialized for reference counts
+ * @refs: atomic_t counter field
+ *
+ * The counter saturates at UINT_MAX and will not move once
+ * there. This avoids wrapping the counter and causing 'spurious'
+ * use-after-free bugs.
+ */
typedef struct refcount_struct {
atomic_t refs;
} refcount_t;
#define REFCOUNT_INIT(n) { .refs = ATOMIC_INIT(n), }
+/**
+ * refcount_set - set a refcount's value
+ * @r: the refcount
+ * @n: value to which the refcount will be set
+ */
static inline void refcount_set(refcount_t *r, unsigned int n)
{
atomic_set(&r->refs, n);
}
+/**
+ * refcount_read - get a refcount's value
+ * @r: the refcount
+ *
+ * Return: the refcount's value
+ */
static inline unsigned int refcount_read(const refcount_t *r)
{
return atomic_read(&r->refs);