1 From ac437762dc04468ae96b618199d2c97c22c7ebc9 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Fri, 6 Jan 2023 10:33:47 -0500
4 Subject: nfsd: allow nfsd_file_get to sanely handle a NULL pointer
6 From: Jeff Layton <jlayton@kernel.org>
8 [ Upstream commit 70f62231cdfd52357836733dd31db787e0412ab2 ]
10 ...and remove some now-useless NULL pointer checks in its callers.
12 Suggested-by: NeilBrown <neilb@suse.de>
13 Signed-off-by: Jeff Layton <jlayton@kernel.org>
14 Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
16 fs/nfsd/filecache.c | 5 ++---
17 fs/nfsd/nfs4state.c | 4 +---
18 2 files changed, 3 insertions(+), 6 deletions(-)
20 diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c
21 index 68c7c82f8b3bb..206742bbbd682 100644
22 --- a/fs/nfsd/filecache.c
23 +++ b/fs/nfsd/filecache.c
24 @@ -451,7 +451,7 @@ static bool nfsd_file_lru_remove(struct nfsd_file *nf)
26 nfsd_file_get(struct nfsd_file *nf)
28 - if (likely(refcount_inc_not_zero(&nf->nf_ref)))
29 + if (nf && refcount_inc_not_zero(&nf->nf_ref))
33 @@ -1106,8 +1106,7 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
35 nf = rhashtable_lookup(&nfsd_file_rhash_tbl, &key,
36 nfsd_file_rhash_params);
38 - nf = nfsd_file_get(nf);
39 + nf = nfsd_file_get(nf);
43 diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
44 index 5c261cc807e8e..628e564e530bf 100644
45 --- a/fs/nfsd/nfs4state.c
46 +++ b/fs/nfsd/nfs4state.c
47 @@ -602,9 +602,7 @@ put_nfs4_file(struct nfs4_file *fi)
48 static struct nfsd_file *
49 __nfs4_get_fd(struct nfs4_file *f, int oflag)
51 - if (f->fi_fds[oflag])
52 - return nfsd_file_get(f->fi_fds[oflag]);
54 + return nfsd_file_get(f->fi_fds[oflag]);
57 static struct nfsd_file *