]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
nfsd: allow nfsd_file_get to sanely handle a NULL pointer
authorJeff Layton <jlayton@kernel.org>
Fri, 6 Jan 2023 15:33:47 +0000 (10:33 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 10 Apr 2024 14:19:26 +0000 (16:19 +0200)
[ Upstream commit 70f62231cdfd52357836733dd31db787e0412ab2 ]

...and remove some now-useless NULL pointer checks in its callers.

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

index 68c7c82f8b3bbb13d7ccebb573e795db4282ad26..206742bbbd68220f3b1e2b48bf138292f67a79ff 100644 (file)
@@ -451,7 +451,7 @@ static bool nfsd_file_lru_remove(struct nfsd_file *nf)
 struct nfsd_file *
 nfsd_file_get(struct nfsd_file *nf)
 {
-       if (likely(refcount_inc_not_zero(&nf->nf_ref)))
+       if (nf && refcount_inc_not_zero(&nf->nf_ref))
                return nf;
        return NULL;
 }
@@ -1106,8 +1106,7 @@ retry:
        rcu_read_lock();
        nf = rhashtable_lookup(&nfsd_file_rhash_tbl, &key,
                               nfsd_file_rhash_params);
-       if (nf)
-               nf = nfsd_file_get(nf);
+       nf = nfsd_file_get(nf);
        rcu_read_unlock();
 
        if (nf) {
index 5c261cc807e8e3b4520c0250e024644009b6bc40..628e564e530bf434180e378d517ca329e7a438bb 100644 (file)
@@ -602,9 +602,7 @@ put_nfs4_file(struct nfs4_file *fi)
 static struct nfsd_file *
 __nfs4_get_fd(struct nfs4_file *f, int oflag)
 {
-       if (f->fi_fds[oflag])
-               return nfsd_file_get(f->fi_fds[oflag]);
-       return NULL;
+       return nfsd_file_get(f->fi_fds[oflag]);
 }
 
 static struct nfsd_file *