diff options
author | 2024-06-22 20:52:39 -0400 | |
---|---|---|
committer | 2024-06-23 00:57:21 -0400 | |
commit | f44cc269a1c148ad83332d85fe54607e8874ca79 (patch) | |
tree | 13c72b423b7756eaa1f588c2165653faaee8dc22 /fs/bcachefs/seqmutex.h | |
parent | bcachefs: Fix freeing of error pointers (diff) | |
download | wireguard-linux-f44cc269a1c148ad83332d85fe54607e8874ca79.tar.xz wireguard-linux-f44cc269a1c148ad83332d85fe54607e8874ca79.zip |
bcachefs: fix seqmutex_relock()
We were grabbing the sequence number before unlock incremented it - fix
this by moving the increment to seqmutex_lock() (so the seqmutex_relock()
failure path skips the mutex_trylock()), and returning the sequence
number from unlock(), to make the API simpler and safer.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to '')
-rw-r--r-- | fs/bcachefs/seqmutex.h | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/fs/bcachefs/seqmutex.h b/fs/bcachefs/seqmutex.h index c1860d8163fb..c4b3d8d3f414 100644 --- a/fs/bcachefs/seqmutex.h +++ b/fs/bcachefs/seqmutex.h @@ -19,17 +19,14 @@ static inline bool seqmutex_trylock(struct seqmutex *lock) static inline void seqmutex_lock(struct seqmutex *lock) { mutex_lock(&lock->lock); -} - -static inline void seqmutex_unlock(struct seqmutex *lock) -{ lock->seq++; - mutex_unlock(&lock->lock); } -static inline u32 seqmutex_seq(struct seqmutex *lock) +static inline u32 seqmutex_unlock(struct seqmutex *lock) { - return lock->seq; + u32 seq = lock->seq; + mutex_unlock(&lock->lock); + return seq; } static inline bool seqmutex_relock(struct seqmutex *lock, u32 seq) |