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

Bart Van Assche posted 33 patches 10 months, 1 week ago
[PATCH RFC 09/33] refcount: Add thread-safety annotations in <linux/refcount.h>
Posted by Bart Van Assche 10 months, 1 week ago
Inform the Clang thread-safety analyzer that refcount_dec_and_mutex_lock()
may lock a mutex.

Cc: Will Deacon <will@kernel.org>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 include/linux/refcount.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/include/linux/refcount.h b/include/linux/refcount.h
index 35f039ecb272..dd854ad27df8 100644
--- a/include/linux/refcount.h
+++ b/include/linux/refcount.h
@@ -98,6 +98,7 @@
 #include <linux/limits.h>
 #include <linux/refcount_types.h>
 #include <linux/spinlock_types.h>
+#include <linux/thread_safety.h>
 
 struct mutex;
 
@@ -353,7 +354,9 @@ static inline void refcount_dec(refcount_t *r)
 
 extern __must_check bool refcount_dec_if_one(refcount_t *r);
 extern __must_check bool refcount_dec_not_one(refcount_t *r);
-extern __must_check bool refcount_dec_and_mutex_lock(refcount_t *r, struct mutex *lock) __cond_acquires(lock);
+__must_check bool refcount_dec_and_mutex_lock(refcount_t *r, struct mutex *lock)
+	__cond_acquires(lock)
+	TRY_ACQUIRE(true, *lock);
 extern __must_check bool refcount_dec_and_lock(refcount_t *r, spinlock_t *lock) __cond_acquires(lock);
 extern __must_check bool refcount_dec_and_lock_irqsave(refcount_t *r,
 						       spinlock_t *lock,