]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
NFSD: only call fh_unlock() once in nfsd_link()
authorNeilBrown <neilb@suse.de>
Tue, 26 Jul 2022 06:45:30 +0000 (16:45 +1000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Apr 2024 14:19:14 +0000 (16:19 +0200)
[ Upstream commit e18bcb33bc5b69bccc2b532075aa00bb49cc01c5 ]

On non-error paths, nfsd_link() calls fh_unlock() twice.  This is safe
because fh_unlock() records that the unlock has been done and doesn't
repeat it.
However it makes the code a little confusing and interferes with changes
that are planned for directory locking.

So rearrange the code to ensure fh_unlock() is called exactly once if
fh_lock() was called.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
fs/nfsd/vfs.c

index 4b1304fe718fd5996817aebcef63e4114513e784..ac716ced1fd5fd567297a08077fb16805939f7a6 100644 (file)
@@ -1542,9 +1542,10 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,
        dirp = d_inode(ddir);
 
        dnew = lookup_one_len(name, ddir, len);
-       host_err = PTR_ERR(dnew);
-       if (IS_ERR(dnew))
-               goto out_nfserr;
+       if (IS_ERR(dnew)) {
+               err = nfserrno(PTR_ERR(dnew));
+               goto out_unlock;
+       }
 
        dold = tfhp->fh_dentry;
 
@@ -1563,17 +1564,17 @@ nfsd_link(struct svc_rqst *rqstp, struct svc_fh *ffhp,
                else
                        err = nfserrno(host_err);
        }
-out_dput:
        dput(dnew);
-out_unlock:
-       fh_unlock(ffhp);
+out_drop_write:
        fh_drop_write(tfhp);
 out:
        return err;
 
-out_nfserr:
-       err = nfserrno(host_err);
-       goto out_unlock;
+out_dput:
+       dput(dnew);
+out_unlock:
+       fh_unlock(ffhp);
+       goto out_drop_write;
 }
 
 static void