@@ -46,18 +46,18 @@ static inline void kref_get(struct kref *kref)
4646}
4747
4848/**
49- * kref_put - decrement refcount for object.
50- * @kref: object.
51- * @release: pointer to the function that will clean up the object when the
49+ * kref_put - Decrement refcount for object
50+ * @kref: Object
51+ * @release: Pointer to the function that will clean up the object when the
5252 * last reference to the object is released.
53- * This pointer is required, and it is not acceptable to pass kfree
54- * in as this function.
5553 *
56- * Decrement the refcount, and if 0, call release().
57- * Return 1 if the object was removed, otherwise return 0. Beware, if this
58- * function returns 0, you still can not count on the kref from remaining in
59- * memory. Only use the return value if you want to see if the kref is now
60- * gone, not present.
54+ * Decrement the refcount, and if 0, call @release. The caller may not
55+ * pass NULL or kfree() as the release function.
56+ *
57+ * Return: 1 if this call removed the object, otherwise return 0. Beware,
58+ * if this function returns 0, another caller may have removed the object
59+ * by the time this function returns. The return value is only certain
60+ * if you want to see if the object is definitely released.
6161 */
6262static inline int kref_put (struct kref * kref , void (* release )(struct kref * kref ))
6363{
@@ -68,17 +68,37 @@ static inline int kref_put(struct kref *kref, void (*release)(struct kref *kref)
6868 return 0 ;
6969}
7070
71+ /**
72+ * kref_put_mutex - Decrement refcount for object
73+ * @kref: Object
74+ * @release: Pointer to the function that will clean up the object when the
75+ * last reference to the object is released.
76+ * @mutex: Mutex which protects the release function.
77+ *
78+ * This variant of kref_lock() calls the @release function with the @mutex
79+ * held. The @release function will release the mutex.
80+ */
7181static inline int kref_put_mutex (struct kref * kref ,
7282 void (* release )(struct kref * kref ),
73- struct mutex * lock )
83+ struct mutex * mutex )
7484{
75- if (refcount_dec_and_mutex_lock (& kref -> refcount , lock )) {
85+ if (refcount_dec_and_mutex_lock (& kref -> refcount , mutex )) {
7686 release (kref );
7787 return 1 ;
7888 }
7989 return 0 ;
8090}
8191
92+ /**
93+ * kref_put_lock - Decrement refcount for object
94+ * @kref: Object
95+ * @release: Pointer to the function that will clean up the object when the
96+ * last reference to the object is released.
97+ * @lock: Spinlock which protects the release function.
98+ *
99+ * This variant of kref_lock() calls the @release function with the @lock
100+ * held. The @release function will release the lock.
101+ */
82102static inline int kref_put_lock (struct kref * kref ,
83103 void (* release )(struct kref * kref ),
84104 spinlock_t * lock )
@@ -94,8 +114,6 @@ static inline int kref_put_lock(struct kref *kref,
94114 * kref_get_unless_zero - Increment refcount for object unless it is zero.
95115 * @kref: object.
96116 *
97- * Return non-zero if the increment succeeded. Otherwise return 0.
98- *
99117 * This function is intended to simplify locking around refcounting for
100118 * objects that can be looked up from a lookup structure, and which are
101119 * removed from that lookup structure in the object destructor.
@@ -105,6 +123,8 @@ static inline int kref_put_lock(struct kref *kref,
105123 * With a lookup followed by a kref_get_unless_zero *with return value check*
106124 * locking in the kref_put path can be deferred to the actual removal from
107125 * the lookup structure and RCU lookups become trivial.
126+ *
127+ * Return: non-zero if the increment succeeded. Otherwise return 0.
108128 */
109129static inline int __must_check kref_get_unless_zero (struct kref * kref )
110130{
0 commit comments