]> git.itanic.dy.fi Git - linux-stable/commitdiff
netfs, fscache: Prevent Oops in fscache_put_cache()
authorDan Carpenter <dan.carpenter@linaro.org>
Fri, 12 Jan 2024 06:59:41 +0000 (09:59 +0300)
committerDavid Howells <dhowells@redhat.com>
Mon, 22 Jan 2024 21:58:35 +0000 (21:58 +0000)
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/
fs/netfs/fscache_cache.c

index d645f8b302a27882c86c3c46e134dd5bcbc35cef..9397ed39b0b4ecbdd9c9b5860887162990c2f66d 100644 (file)
@@ -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);