This issue is found when creating /dev/sdtest with flags (O_CREAT | O_DIRECT). The file still can be retrieved even after system reports failure (-EINVAL) for it. Reporting error on creating the file is correct behaviour because either devtmpfs or tmpfs doesn't support O_DIRECT for regular file. However, it's incorrect that the file is still existing. The cause is the newly allocated dentry and inode aren't released on failure in do_last(). # rm /dev/sdtest # dd if=/dev/urandom of=/dev/sdtest bs=4k count=1 oflag=direct <-EINVAL is returned> # ls /dev/sdtest <File is still existing> This fixes the issue by releasing the dentry, thus the inode on failure in do_last(). With this applied, the file (/dev/sdtest) isn't seen in this scenario. Reported-by: YouYou <youyou.wy.huang@xxxxxxxxxxx> Signed-off-by: Gavin Shan <dubo.sgw@xxxxxxxxxxxxxxx> Signed-off-by: Liguang Zhang <liguang.zlg@xxxxxxxxxxxxxxx> Signed-off-by: Ahao Mu <ahao.mah@xxxxxxxxxxxxxxx> --- fs/namei.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/namei.c b/fs/namei.c index 9cc91fb..607c357 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3382,6 +3382,8 @@ static int do_last(struct nameidata *nd, *opened |= FILE_OPENED; opened: error = open_check_o_direct(file); + if (error && (*opened & FILE_OPENED)) + dput(path.dentry); if (!error) error = ima_file_check(file, op->acc_mode, *opened); if (!error && will_truncate) -- 1.8.3.1