From: Christoph Hellwig <hch@lst.de>
To: Carlos Maiolino <cem@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Cc: "Luc Van Oostenryck" <luc.vanoostenryck@gmail.com>,
Chris Li <sparse@chrisli.org>,
linux-sparse@vger.kernel.org, linux-xfs@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH 1/3] lockref: add a __cond_lock annotation for lockref_put_or_lock
Date: Fri, 14 Nov 2025 06:52:23 +0100 [thread overview]
Message-ID: <20251114055249.1517520-2-hch@lst.de> (raw)
In-Reply-To: <20251114055249.1517520-1-hch@lst.de>
Add a cond_lock annotation for lockref_put_or_lock to make sparse
happy with using it. Note that for this the return value has to be
double-inverted as the return value convention of lockref_put_or_lock
is inverted compared to _trylock conventions expected by __cond_lock,
as lockref_put_or_lock returns true when it did not need to take the
lock.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/linux/lockref.h | 4 +++-
lib/lockref.c | 4 ++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/include/linux/lockref.h b/include/linux/lockref.h
index 676721ee878d..7b4bb67db216 100644
--- a/include/linux/lockref.h
+++ b/include/linux/lockref.h
@@ -49,7 +49,9 @@ static inline void lockref_init(struct lockref *lockref)
void lockref_get(struct lockref *lockref);
int lockref_put_return(struct lockref *lockref);
bool lockref_get_not_zero(struct lockref *lockref);
-bool lockref_put_or_lock(struct lockref *lockref);
+bool _lockref_put_or_lock(struct lockref *lockref);
+#define lockref_put_or_lock(_lockref) \
+ (!__cond_lock((_lockref)->lock, !_lockref_put_or_lock(_lockref)))
void lockref_mark_dead(struct lockref *lockref);
bool lockref_get_not_dead(struct lockref *lockref);
diff --git a/lib/lockref.c b/lib/lockref.c
index 5d8e3ef3860e..667f0c30c867 100644
--- a/lib/lockref.c
+++ b/lib/lockref.c
@@ -105,7 +105,7 @@ EXPORT_SYMBOL(lockref_put_return);
* @lockref: pointer to lockref structure
* Return: 1 if count updated successfully or 0 if count <= 1 and lock taken
*/
-bool lockref_put_or_lock(struct lockref *lockref)
+bool _lockref_put_or_lock(struct lockref *lockref)
{
CMPXCHG_LOOP(
new.count--;
@@ -122,7 +122,7 @@ bool lockref_put_or_lock(struct lockref *lockref)
spin_unlock(&lockref->lock);
return true;
}
-EXPORT_SYMBOL(lockref_put_or_lock);
+EXPORT_SYMBOL(_lockref_put_or_lock);
/**
* lockref_mark_dead - mark lockref dead
--
2.47.3
next prev parent reply other threads:[~2025-11-14 5:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-14 5:52 make xfs sparse-warning free Christoph Hellwig
2025-11-14 5:52 ` Christoph Hellwig [this message]
2025-11-14 18:18 ` [PATCH 1/3] lockref: add a __cond_lock annotation for lockref_put_or_lock Linus Torvalds
2025-11-18 5:58 ` Christoph Hellwig
2025-11-14 5:52 ` [PATCH 2/3] xfs: move some code out of xfs_iget_recycle Christoph Hellwig
2025-11-14 17:04 ` Darrick J. Wong
2025-11-14 17:28 ` Linus Torvalds
2025-11-18 5:59 ` Christoph Hellwig
2025-11-14 5:52 ` [PATCH 3/3] xfs: work around sparse context tracking in xfs_qm_dquot_isolate Christoph Hellwig
2025-11-14 17:06 ` Darrick J. Wong
2025-11-18 6:00 ` Christoph Hellwig
2025-11-14 17:56 ` make xfs sparse-warning free Linus Torvalds
2025-11-18 5:57 ` Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251114055249.1517520-2-hch@lst.de \
--to=hch@lst.de \
--cc=akpm@linux-foundation.org \
--cc=cem@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sparse@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=luc.vanoostenryck@gmail.com \
--cc=sparse@chrisli.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).