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

From: Yangtao Li
Date: Tue May 09 2023 - 05:57:45 EST


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@xxxxxxxx>
---
fs/f2fs/file.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)

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;
--
2.39.0