]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
9p: simplify v9fs_vfs_atomic_open()
authorAl Viro <viro@zeniv.linux.org.uk>
Fri, 12 Sep 2025 15:28:20 +0000 (11:28 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Wed, 17 Sep 2025 03:59:38 +0000 (23:59 -0400)
if v9fs_vfs_lookup() returns a preexisting alias, it is guaranteed to be
positive.  IOW, in that case we will immediately return finish_no_open(),
leaving only the case res == NULL past that point.

Reviewed-by: NeilBrown <neil@brown.name>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/9p/vfs_inode.c

index 399d455d50d626f300ad9b3e4a13aadbaf37e550..d0c77ec31b1dd66416c78d285d9ed91802d9cf42 100644 (file)
@@ -768,22 +768,18 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
        struct v9fs_inode __maybe_unused *v9inode;
        struct v9fs_session_info *v9ses;
        struct p9_fid *fid;
-       struct dentry *res = NULL;
        struct inode *inode;
        int p9_omode;
 
        if (d_in_lookup(dentry)) {
-               res = v9fs_vfs_lookup(dir, dentry, 0);
-               if (IS_ERR(res))
-                       return PTR_ERR(res);
-
-               if (res)
-                       dentry = res;
+               struct dentry *res = v9fs_vfs_lookup(dir, dentry, 0);
+               if (res || d_really_is_positive(dentry))
+                       return finish_no_open(file, res);
        }
 
        /* Only creates */
-       if (!(flags & O_CREAT) || d_really_is_positive(dentry))
-               return finish_no_open(file, res);
+       if (!(flags & O_CREAT))
+               return finish_no_open(file, NULL);
 
        v9ses = v9fs_inode2v9ses(dir);
        perm = unixmode2p9mode(v9ses, mode);
@@ -795,17 +791,17 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
                        "write-only file with writeback enabled, creating w/ O_RDWR\n");
        }
        fid = v9fs_create(v9ses, dir, dentry, NULL, perm, p9_omode);
-       if (IS_ERR(fid)) {
-               err = PTR_ERR(fid);
-               goto error;
-       }
+       if (IS_ERR(fid))
+               return PTR_ERR(fid);
 
        v9fs_invalidate_inode_attr(dir);
        inode = d_inode(dentry);
        v9inode = V9FS_I(inode);
        err = finish_open(file, dentry, generic_file_open);
-       if (err)
-               goto error;
+       if (unlikely(err)) {
+               p9_fid_put(fid);
+               return err;
+       }
 
        file->private_data = fid;
 #ifdef CONFIG_9P_FSCACHE
@@ -818,13 +814,7 @@ v9fs_vfs_atomic_open(struct inode *dir, struct dentry *dentry,
        v9fs_open_fid_add(inode, &fid);
 
        file->f_mode |= FMODE_CREATED;
-out:
-       dput(res);
-       return err;
-
-error:
-       p9_fid_put(fid);
-       goto out;
+       return 0;
 }
 
 /**