[PATCH RFC 09/33] refcount: Add thread-safety annotations in <linux/refcount.h>
From: Bart Van Assche
Date: Thu Feb 06 2025 - 12:52:59 EST
Inform the Clang thread-safety analyzer that refcount_dec_and_mutex_lock()
may lock a mutex.
Cc: Will Deacon <will@xxxxxxxxxx>
Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
---
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,