Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lockref: add a __cond_lock annotation for lockref_put_or_lock

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>

authored by

Christoph Hellwig and committed by
Linus Torvalds
12eef14b c752c21c

+3
+2
include/linux/lockref.h
··· 50 50 int lockref_put_return(struct lockref *lockref); 51 51 bool lockref_get_not_zero(struct lockref *lockref); 52 52 bool lockref_put_or_lock(struct lockref *lockref); 53 + #define lockref_put_or_lock(_lockref) \ 54 + (!__cond_lock((_lockref)->lock, !lockref_put_or_lock(_lockref))) 53 55 54 56 void lockref_mark_dead(struct lockref *lockref); 55 57 bool lockref_get_not_dead(struct lockref *lockref);
+1
lib/lockref.c
··· 105 105 * @lockref: pointer to lockref structure 106 106 * Return: 1 if count updated successfully or 0 if count <= 1 and lock taken 107 107 */ 108 + #undef lockref_put_or_lock 108 109 bool lockref_put_or_lock(struct lockref *lockref) 109 110 { 110 111 CMPXCHG_LOOP(