vfs: fix up the assert in i_readcount_dec
authorMateusz Guzik <mjguzik@gmail.com>
Fri, 11 Aug 2023 19:48:14 +0000 (21:48 +0200)
committerChristian Brauner <brauner@kernel.org>
Tue, 15 Aug 2023 06:32:45 +0000 (08:32 +0200)
Drops a race where 2 threads could spot a positive value and both
proceed to dec to -1, without reporting anything.

Signed-off-by: Mateusz Guzik <mjguzik@gmail.com>
Message-Id: <20230811194814.1612336-1-mjguzik@gmail.com>
Signed-off-by: Christian Brauner <brauner@kernel.org>
include/linux/fs.h

index 11055d0..57e2a0a 100644 (file)
@@ -2607,8 +2607,7 @@ static inline bool inode_is_open_for_write(const struct inode *inode)
 #if defined(CONFIG_IMA) || defined(CONFIG_FILE_LOCKING)
 static inline void i_readcount_dec(struct inode *inode)
 {
-       BUG_ON(!atomic_read(&inode->i_readcount));
-       atomic_dec(&inode->i_readcount);
+       BUG_ON(atomic_dec_return(&inode->i_readcount) < 0);
 }
 static inline void i_readcount_inc(struct inode *inode)
 {