OSDN Git Service

do_last(): merge the may_open() calls
authorAl Viro <viro@zeniv.linux.org.uk>
Sun, 26 Jan 2020 15:06:13 +0000 (10:06 -0500)
committerAl Viro <viro@zeniv.linux.org.uk>
Sat, 14 Mar 2020 01:09:12 +0000 (21:09 -0400)
have FMODE_OPENED case rejoin the main path at earlier point

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/namei.c

index 7e932d9..2f8a5d3 100644 (file)
@@ -3207,10 +3207,7 @@ static const char *do_last(struct nameidata *nd,
                audit_inode(nd->name, file->f_path.dentry, 0);
                dput(nd->path.dentry);
                nd->path.dentry = dentry;
-               error = may_open(&nd->path, acc_mode, open_flag);
-               if (error)
-                       goto out;
-               goto opened;
+               goto finish_open_created;
        }
 
        if (file->f_mode & FMODE_CREATED) {
@@ -3277,11 +3274,10 @@ finish_open_created:
        error = may_open(&nd->path, acc_mode, open_flag);
        if (error)
                goto out;
-       BUG_ON(file->f_mode & FMODE_OPENED); /* once it's opened, it's opened */
-       error = vfs_open(&nd->path, file);
+       if (!(file->f_mode & FMODE_OPENED))
+               error = vfs_open(&nd->path, file);
        if (error)
                goto out;
-opened:
        error = ima_file_check(file, op->acc_mode);
        if (!error && will_truncate)
                error = handle_truncate(file);