mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] vfs: fix up the assert in i_readcount_dec
@ 2023-08-11 19:48 Mateusz Guzik
  2023-08-14 15:52 ` Christian Brauner
  0 siblings, 1 reply; 2+ messages in thread
From: Mateusz Guzik @ 2023-08-11 19:48 UTC (permalink / raw)
  To: brauner; +Cc: viro, linux-kernel, Mateusz Guzik

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>
---
 include/linux/fs.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 562f2623c9c9..21c8f8ae014d 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2613,8 +2613,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)
 {
-- 
2.39.2


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-14 15:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-11 19:48 [PATCH] vfs: fix up the assert in i_readcount_dec Mateusz Guzik
2023-08-14 15:52 ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®