[PATCH 2/3] fscache: Add missing unhash
From: David Howells
Date: Mon Mar 11 2019 - 10:50:55 EST
In __fscache_acquire_cookie() if fscache_acquire_non_index_cookie() fails,
we clean up and return NULL (indicating no cookie) - however, we don't
unhash the previously hashed object first.
Fix this by moving the failure code out of the main path through the
function to its own goto label and add the missing fscache_unhash_cookie()
call.
Moving the code out to its own label allows the remaining part of the
if-statement to be simplified also.
Fixes: ec0328e46d6e ("fscache: Maintain a catalogue of allocated cookies")
Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
---
fs/fscache/cookie.c | 26 ++++++++++++--------------
1 file changed, 12 insertions(+), 14 deletions(-)
diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
index 75d0ffd36ac0..6931e45b7d59 100644
--- a/fs/fscache/cookie.c
+++ b/fs/fscache/cookie.c
@@ -346,20 +346,10 @@ struct fscache_cookie *__fscache_acquire_cookie(
/* if the object is an index then we need do nothing more here
* - we create indices on disk when we need them as an index
* may exist in multiple caches */
- if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX) {
- if (fscache_acquire_non_index_cookie(cookie, object_size) == 0) {
- set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
- } else {
- atomic_dec(&parent->n_children);
- fscache_cookie_put(cookie,
- fscache_cookie_put_acquire_nobufs);
- fscache_stat(&fscache_n_acquires_nobufs);
- _leave(" = NULL");
- return NULL;
- }
- } else {
- set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
- }
+ if (cookie->type != FSCACHE_COOKIE_TYPE_INDEX &&
+ fscache_acquire_non_index_cookie(cookie, object_size) < 0)
+ goto failed;
+ set_bit(FSCACHE_COOKIE_ENABLED, &cookie->flags);
}
fscache_stat(&fscache_n_acquires_ok);
@@ -367,6 +357,14 @@ struct fscache_cookie *__fscache_acquire_cookie(
out:
fscache_free_cookie(candidate);
return cookie;
+
+failed:
+ atomic_dec(&parent->n_children);
+ fscache_unhash_cookie(cookie);
+ fscache_cookie_put(cookie, fscache_cookie_put_acquire_nobufs);
+ fscache_stat(&fscache_n_acquires_nobufs);
+ _leave(" = NULL");
+ return NULL;
}
EXPORT_SYMBOL(__fscache_acquire_cookie);