[4/4] f2fs: move the conditional statement to hold the inode lock in f2fs_reserve_compress_blocks()

Message ID 20230509095706.17844-4-frank.li@vivo.com
State New
Headers
Series [1/4] f2fs: convert to use sbi directly |

Commit Message

李扬韬 May 9, 2023, 9:57 a.m. UTC
  For judging the inode flag state, the inode lock must be held.

Fixes: c75488fb4d82 ("f2fs: introduce F2FS_IOC_RESERVE_COMPRESS_BLOCKS")
Signed-off-by: Yangtao Li <frank.li@vivo.com>
---
 fs/f2fs/file.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
  

Patch

diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 32dc9a250a36..0959cc3e6394 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3641,9 +3641,6 @@  static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
 	if (!f2fs_sb_has_compression(sbi))
 		return -EOPNOTSUPP;
 
-	if (!f2fs_compressed_file(inode))
-		return -EINVAL;
-
 	if (f2fs_readonly(sbi->sb))
 		return -EROFS;
 
@@ -3658,6 +3655,11 @@  static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg)
 
 	inode_lock(inode);
 
+	if (!f2fs_compressed_file(inode)) {
+		ret = -EINVAL;
+		goto unlock_inode;
+	}
+
 	if (!is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) {
 		ret = -EINVAL;
 		goto unlock_inode;