mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2, resend] lockref: add a __cond_lock annotation for lockref_put_or_lock
@ 2025-12-09  8:18 Christoph Hellwig
  2025-12-09 20:53 ` Linus Torvalds
  0 siblings, 1 reply; 2+ messages in thread
From: Christoph Hellwig @ 2025-12-09  8:18 UTC (permalink / raw)
  To: Andrew Morton, Linus Torvalds; +Cc: linux-kernel

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 | 2 ++
 lib/lockref.c           | 1 +
 2 files changed, 3 insertions(+)

diff --git a/include/linux/lockref.h b/include/linux/lockref.h
index 676721ee878d..815d871fadfc 100644
--- a/include/linux/lockref.h
+++ b/include/linux/lockref.h
@@ -50,6 +50,8 @@ 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);
+#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..9210fc6ae714 100644
--- a/lib/lockref.c
+++ b/lib/lockref.c
@@ -105,6 +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
  */
+#undef lockref_put_or_lock
 bool lockref_put_or_lock(struct lockref *lockref)
 {
 	CMPXCHG_LOOP(
-- 
2.47.3


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2, resend] lockref: add a __cond_lock annotation for lockref_put_or_lock
  2025-12-09  8:18 [PATCH v2, resend] lockref: add a __cond_lock annotation for lockref_put_or_lock Christoph Hellwig
@ 2025-12-09 20:53 ` Linus Torvalds
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Torvalds @ 2025-12-09 20:53 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Andrew Morton, linux-kernel

On Tue, 9 Dec 2025 at 17:19, Christoph Hellwig <hch@lst.de> wrote:
>
> Add a cond_lock annotation for lockref_put_or_lock to make sparse
> happy with using it.

I'll just take this directly so that we'll have this done this merge window.

Thanks,
        Linus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-12-09 20:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-09  8:18 [PATCH v2, resend] lockref: add a __cond_lock annotation for lockref_put_or_lock Christoph Hellwig
2025-12-09 20:53 ` Linus Torvalds

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®