lockref: add a __cond_lock annotation for lockref_put_or_lock
PATCH RESEND v2 1/1 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 <[email protected]>
--- include/linux/lockref.h | 2 ++ lib/lockref.c | 1 + 2 files changed, 3 insertions(+)
include/linux/lockref.h +2 -0
@@ -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);
lib/lockref.c +1 -0
@@ -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_lockbool lockref_put_or_lock (struct lockref *lockref) { CMPXCHG_LOOP(
Signature · 1 line
2.47.3
Quoted 3 lines · Christoph Hellwig
Add a
cond_lockannotation forlockref_put_or_lockto make sparse happy with using it.
I'll just take this directly so that we'll have this done this merge window.
Thanks,
Linus