aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/refcount.h
diff options
context:
space:
mode:
authorDavid Windsor <dwindsor@gmail.com>2017-03-10 10:34:12 -0500
committerIngo Molnar <mingo@kernel.org>2017-03-13 02:41:08 -0400
commitbd174169c7a12a37b3b4aa2221f084ade010b182 (patch)
treee2be1ee97039943699fe637804c86bbe6626a23c /include/linux/refcount.h
parent4495c08e84729385774601b5146d51d9e5849f81 (diff)
locking/refcount: Add refcount_t API kernel-doc comments
Signed-off-by: David Windsor <dwindsor@gmail.com> Acked-by: Peter Zijlstra <peterz@infradead.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: elena.reshetova@intel.com Cc: kernel-hardening@lists.openwall.com Link: http://lkml.kernel.org/r/1489160052-20293-1-git-send-email-dwindsor@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
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 @@
6#include <linux/spinlock.h> 6#include <linux/spinlock.h>
7#include <linux/kernel.h> 7#include <linux/kernel.h>
8 8
9/**
10 * refcount_t - variant of atomic_t specialized for reference counts
11 * @refs: atomic_t counter field
12 *
13 * The counter saturates at UINT_MAX and will not move once
14 * there. This avoids wrapping the counter and causing 'spurious'
15 * use-after-free bugs.
16 */
9typedef struct refcount_struct { 17typedef struct refcount_struct {
10 atomic_t refs; 18 atomic_t refs;
11} refcount_t; 19} refcount_t;
12 20
13#define REFCOUNT_INIT(n) { .refs = ATOMIC_INIT(n), } 21#define REFCOUNT_INIT(n) { .refs = ATOMIC_INIT(n), }
14 22
23/**
24 * refcount_set - set a refcount's value
25 * @r: the refcount
26 * @n: value to which the refcount will be set
27 */
15static inline void refcount_set(refcount_t *r, unsigned int n) 28static inline void refcount_set(refcount_t *r, unsigned int n)
16{ 29{
17 atomic_set(&r->refs, n); 30 atomic_set(&r->refs, n);
18} 31}
19 32
33/**
34 * refcount_read - get a refcount's value
35 * @r: the refcount
36 *
37 * Return: the refcount's value
38 */
20static inline unsigned int refcount_read(const refcount_t *r) 39static inline unsigned int refcount_read(const refcount_t *r)
21{ 40{
22 return atomic_read(&r->refs); 41 return atomic_read(&r->refs);