In preparation for using vfs_create_no_perm() in lookup_open() we need to move setting FMODE_CREATED on the file mode to either before or after that call, as currently it is in the middle. If try_break_deleg() fails it is currently not set, but vfs_create_no_perm() includes a try_break_deleg(). Going up the call chain of lookup_open() we see that it is only used in open_last_lookups() if no error is returned from lookup_open(), so we can safely move it to after the filesystem create() call. This also makes more sense when reading the code as you don't have to wonder what the implications are of setting FMODE_CREATED before the create() call. Signed-off-by: Jori Koolstra Reviewed-by: NeilBrown --- fs/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/namei.c b/fs/namei.c index 85ce44b068c1..a7e179366703 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4550,7 +4550,6 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, if (error) goto out_dput; - file->f_mode |= FMODE_CREATED; if (!dir_inode->i_op->create) { error = -EACCES; goto out_dput; @@ -4562,6 +4561,7 @@ static struct dentry *lookup_open(struct nameidata *nd, struct file *file, goto out_dput; fsnotify_create(dir_inode, dentry); + file->f_mode |= FMODE_CREATED; return dentry; -- 2.54.0