Skip to content

Commit 12eef14

Browse files
Christoph Hellwigtorvalds
authored andcommitted
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>
1 parent c752c21 commit 12eef14

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

include/linux/lockref.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ void lockref_get(struct lockref *lockref);
5050
int lockref_put_return(struct lockref *lockref);
5151
bool lockref_get_not_zero(struct lockref *lockref);
5252
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)))
5355

5456
void lockref_mark_dead(struct lockref *lockref);
5557
bool lockref_get_not_dead(struct lockref *lockref);

lib/lockref.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ EXPORT_SYMBOL(lockref_put_return);
105105
* @lockref: pointer to lockref structure
106106
* Return: 1 if count updated successfully or 0 if count <= 1 and lock taken
107107
*/
108+
#undef lockref_put_or_lock
108109
bool lockref_put_or_lock(struct lockref *lockref)
109110
{
110111
CMPXCHG_LOOP(

0 commit comments

Comments
 (0)