summaryrefslogtreecommitdiff
path: root/fs/netfs
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@linaro.org>2024-01-12 09:59:41 +0300
committerDavid Howells <dhowells@redhat.com>2024-01-23 00:58:35 +0300
commit3be0b3ed1d76c6703b9ee482b55f7e01c369cc68 (patch)
treedf6e39a7252a09c3794e194ef2f7d6611045ab61 /fs/netfs
parentc40497d82387188f14d9adc4caa58ee1cb1999e1 (diff)
downloadlinux-3be0b3ed1d76c6703b9ee482b55f7e01c369cc68.tar.xz
netfs, fscache: Prevent Oops in fscache_put_cache()
This function dereferences "cache" and then checks if it's IS_ERR_OR_NULL(). Check first, then dereference. Fixes: 9549332df4ed ("fscache: Implement cache registration") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Signed-off-by: David Howells <dhowells@redhat.com> Link: https://lore.kernel.org/r/e84bc740-3502-4f16-982a-a40d5676615c@moroto.mountain/ # v2
Diffstat (limited to 'fs/netfs')
-rw-r--r--fs/netfs/fscache_cache.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/fs/netfs/fscache_cache.c b/fs/netfs/fscache_cache.c
index d645f8b302a2..9397ed39b0b4 100644
--- a/fs/netfs/fscache_cache.c
+++ b/fs/netfs/fscache_cache.c
@@ -179,13 +179,14 @@ EXPORT_SYMBOL(fscache_acquire_cache);
void fscache_put_cache(struct fscache_cache *cache,
enum fscache_cache_trace where)
{
- unsigned int debug_id = cache->debug_id;
+ unsigned int debug_id;
bool zero;
int ref;
if (IS_ERR_OR_NULL(cache))
return;
+ debug_id = cache->debug_id;
zero = __refcount_dec_and_test(&cache->ref, &ref);
trace_fscache_cache(debug_id, ref - 1, where);