History

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.

Christoph Hellwig committed 11 months ago

Commit 12eef141 parent c752c212 files · +3 −0Browse files

Unified · Split

2 files
  1. include/linux/lockref.h +2 −0
  2. lib/lockref.c +1 −0
include/linux/lockref.h+2−0
@@ -50,6 +50,8 @@ void lockref_get(struct lockref *lockref); · 49 unmodified lines
50int lockref_put_return(struct lockref *lockref);50int lockref_put_return(struct lockref *lockref);
51bool lockref_get_not_zero(struct lockref *lockref);51bool lockref_get_not_zero(struct lockref *lockref);
52bool lockref_put_or_lock(struct lockref *lockref);52bool 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
54void lockref_mark_dead(struct lockref *lockref);56void lockref_mark_dead(struct lockref *lockref);
55bool lockref_get_not_dead(struct lockref *lockref);57bool lockref_get_not_dead(struct lockref *lockref);
lib/lockref.c+1−0
@@ -105,6 +105,7 @@ EXPORT_SYMBOL(lockref_put_return); · 104 unmodified lines
105 * @lockref: pointer to lockref structure105 * @lockref: pointer to lockref structure
106 * Return: 1 if count updated successfully or 0 if count <= 1 and lock taken106 * Return: 1 if count updated successfully or 0 if count <= 1 and lock taken
107 */107 */
108#undef lockref_put_or_lock
108bool lockref_put_or_lock(struct lockref *lockref)109bool lockref_put_or_lock(struct lockref *lockref)
109{110{
110 CMPXCHG_LOOP(111 CMPXCHG_LOOP(