diff options
author | Jeff Layton <jlayton@kernel.org> | 2023-01-06 10:33:47 -0500 |
---|---|---|
committer | Sasha Levin <sashal@kernel.org> | 2024-03-26 18:20:22 -0400 |
commit | 7762c2d4cc0b6a1c4682e7fd01f0586f028aeba4 (patch) | |
tree | 0419ad24ef4afa685bbe8d6960274f2e5b924927 /fs/nfsd | |
parent | a3812a47a32022ca76bf46ddacdd823dc2aabf8b (diff) |
nfsd: allow nfsd_file_get to sanely handle a NULL pointer
[ 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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'fs/nfsd')
-rw-r--r-- | fs/nfsd/filecache.c | 5 | ||||
-rw-r--r-- | fs/nfsd/nfs4state.c | 4 |
2 files changed, 3 insertions, 6 deletions
diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 697acf5c3c68..6e8712bd7c99 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -431,7 +431,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; } @@ -1086,8 +1086,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) { diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index b9d694ec25d1..e4522e86e984 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -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 * |