[tip: locking/core] kref: Add context-analysis annotations

From: tip-bot2 for Marco Elver
Date: Mon Jan 05 2026 - 11:04:11 EST


The following commit has been merged into the locking/core branch of tip:

Commit-ID: 5e256db9325e75e9f000ddd64e4f1dbd2a6d8acd
Gitweb: https://git.kernel.org/tip/5e256db9325e75e9f000ddd64e4f1dbd2a6d8acd
Author: Marco Elver <elver@xxxxxxxxxx>
AuthorDate: Fri, 19 Dec 2025 16:40:05 +01:00
Committer: Peter Zijlstra <peterz@xxxxxxxxxxxxx>
CommitterDate: Mon, 05 Jan 2026 16:43:31 +01:00

kref: Add context-analysis annotations

Mark functions that conditionally acquire the passed lock.

Signed-off-by: Marco Elver <elver@xxxxxxxxxx>
Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
Reviewed-by: Bart Van Assche <bvanassche@xxxxxxx>
Link: https://patch.msgid.link/20251219154418.3592607-17-elver@xxxxxxxxxx
---
include/linux/kref.h | 2 ++
1 file changed, 2 insertions(+)

diff --git a/include/linux/kref.h b/include/linux/kref.h
index 88e82ab..9bc6abe 100644
--- a/include/linux/kref.h
+++ b/include/linux/kref.h
@@ -81,6 +81,7 @@ 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)
+ __cond_acquires(true, mutex)
{
if (refcount_dec_and_mutex_lock(&kref->refcount, mutex)) {
release(kref);
@@ -102,6 +103,7 @@ static inline int kref_put_mutex(struct kref *kref,
static inline int kref_put_lock(struct kref *kref,
void (*release)(struct kref *kref),
spinlock_t *lock)
+ __cond_acquires(true, lock)
{
if (refcount_dec_and_lock(&kref->refcount, lock)) {
release(kref);