]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lockref: add a __cond_lock annotation for lockref_put_or_lock
authorChristoph Hellwig <hch@lst.de>
Tue, 9 Dec 2025 08:18:57 +0000 (09:18 +0100)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 9 Dec 2025 20:58:51 +0000 (05:58 +0900)
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>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
include/linux/lockref.h
lib/lockref.c

index 676721ee878d766fa4bdc02baef890f4f795e99d..815d871fadfcbb437517e64e8b46c6260f0af547 100644 (file)
@@ -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);
index 5d8e3ef3860ee1290dbde1d01edb6f992b60fac5..9210fc6ae71499b2e945f731b30fa44c2ee433c4 100644 (file)
@@ -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(