]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-5.15/nfsd-allow-nfsd_file_get-to-sanely-handle-a-null-poi.patch
Fixes for 5.15
[thirdparty/kernel/stable-queue.git] / queue-5.15 / nfsd-allow-nfsd_file_get-to-sanely-handle-a-null-poi.patch
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
5
6 From: Jeff Layton <jlayton@kernel.org>
7
8 [ Upstream commit 70f62231cdfd52357836733dd31db787e0412ab2 ]
9
10 ...and remove some now-useless NULL pointer checks in its callers.
11
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>
15 ---
16 fs/nfsd/filecache.c | 5 ++---
17 fs/nfsd/nfs4state.c | 4 +---
18 2 files changed, 3 insertions(+), 6 deletions(-)
19
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)
25 struct nfsd_file *
26 nfsd_file_get(struct nfsd_file *nf)
27 {
28 - if (likely(refcount_inc_not_zero(&nf->nf_ref)))
29 + if (nf && refcount_inc_not_zero(&nf->nf_ref))
30 return nf;
31 return NULL;
32 }
33 @@ -1106,8 +1106,7 @@ nfsd_file_do_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,
34 rcu_read_lock();
35 nf = rhashtable_lookup(&nfsd_file_rhash_tbl, &key,
36 nfsd_file_rhash_params);
37 - if (nf)
38 - nf = nfsd_file_get(nf);
39 + nf = nfsd_file_get(nf);
40 rcu_read_unlock();
41
42 if (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)
50 {
51 - if (f->fi_fds[oflag])
52 - return nfsd_file_get(f->fi_fds[oflag]);
53 - return NULL;
54 + return nfsd_file_get(f->fi_fds[oflag]);
55 }
56
57 static struct nfsd_file *
58 --
59 2.43.0
60