[PATCH RFC 08/33] kref: Add thread-safety annotations in <linux/kref.h>

Bart Van Assche posted 33 patches 10 months, 1 week ago
[PATCH RFC 08/33] kref: Add thread-safety annotations in <linux/kref.h>
Posted by Bart Van Assche 10 months, 1 week ago
Inform the Clang thread-safety analyzer that kref_put_mutex() callers
must not hold *mutex.

Note: annotating that the 'release' function pointer releases 'mutex' is
not possible because the mutex pointer is not an argument of the 'release'
function.

Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 include/linux/kref.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/kref.h b/include/linux/kref.h
index 88e82ab1367c..29c31b103557 100644
--- a/include/linux/kref.h
+++ b/include/linux/kref.h
@@ -15,6 +15,7 @@
 
 #include <linux/spinlock.h>
 #include <linux/refcount.h>
+#include <linux/thread_safety.h>
 
 struct kref {
 	refcount_t refcount;
@@ -81,6 +82,8 @@ static inline int kref_put(struct kref *kref, void (*release)(struct kref *kref)
 static inline int kref_put_mutex(struct kref *kref,
 				 void (*release)(struct kref *kref),
 				 struct mutex *mutex)
+	EXCLUDES(*mutex)
+	NO_THREAD_SAFETY_ANALYSIS
 {
 	if (refcount_dec_and_mutex_lock(&kref->refcount, mutex)) {
 		release(kref);