@@ -1801,9 +1801,18 @@ static long f2fs_fallocate(struct file *file, int mode,
if (!S_ISREG(inode->i_mode))
return -EINVAL;
+ if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
+ FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE |
+ FALLOC_FL_INSERT_RANGE))
+ return -EOPNOTSUPP;
+
+ inode_lock(inode);
+
if (IS_ENCRYPTED(inode) &&
- (mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE)))
+ (mode & (FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_INSERT_RANGE))) {
+ inode_unlock(inode);
return -EOPNOTSUPP;
+ }
/*
* Pinned file should not support partial truncation since the block
@@ -1811,15 +1820,10 @@ static long f2fs_fallocate(struct file *file, int mode,
*/
if ((f2fs_compressed_file(inode) || f2fs_is_pinned_file(inode)) &&
(mode & (FALLOC_FL_PUNCH_HOLE | FALLOC_FL_COLLAPSE_RANGE |
- FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE)))
- return -EOPNOTSUPP;
-
- if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE |
- FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE |
- FALLOC_FL_INSERT_RANGE))
+ FALLOC_FL_ZERO_RANGE | FALLOC_FL_INSERT_RANGE))) {
+ inode_unlock(inode);
return -EOPNOTSUPP;
-
- inode_lock(inode);
+ }
ret = file_modified(file);
if (ret)
For judging the inode flag state, the inode lock must be held. Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Fixes: fcc85a4d86b5 ("f2fs crypto: activate encryption support for fs APIs") Signed-off-by: Yangtao Li <frank.li@vivo.com> --- v2: -add unlock fs/f2fs/file.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-)