Skip to content

Commit

Permalink
netfs, fscache: Prevent Oops in fscache_put_cache()
Browse files Browse the repository at this point in the history
This function dereferences "cache" and then checks if it's
IS_ERR_OR_NULL().  Check first, then dereference.

Fixes: 9549332 ("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
  • Loading branch information
Dan Carpenter authored and David Howells committed Jan 22, 2024
1 parent c40497d commit 3be0b3e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion fs/netfs/fscache_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 3be0b3e

Please sign in to comment.