linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: lists@nerdbynature.de
Cc: linux-kernel@vger.kernel.org, anna.schumaker@netapp.com,
	steved@redhat.com, dhowells@redhat.com
Subject: [PATCH 2/3] fscache: Add missing unhash
Date: Mon, 11 Mar 2019 14:50:52 +0000	[thread overview]
Message-ID: <155231585225.2992.10345384716639884052.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <2827.1552315718@warthog.procyon.org.uk>

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@redhat.com>
---

 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);
 


  parent reply	other threads:[~2019-03-11 14:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-06  0:24 FS-Cache: Duplicate cookie detected Christian Kujau
2019-03-06 13:16 ` David Howells
2019-03-06 17:20 ` David Howells
2019-03-06 17:56   ` Christian Kujau
2019-03-08 14:49   ` David Howells
2019-03-08 17:57     ` Christian Kujau
2019-03-08 23:15     ` Christian Kujau
2019-03-08 23:25       ` Christian Kujau
2019-03-11 14:48     ` David Howells
2019-03-11 14:50       ` [PATCH 1/3] fscache: Fix cookie collision David Howells
2019-03-11 14:50       ` David Howells [this message]
2019-03-11 14:50       ` [PATCH 3/3] fscache: Print cookie debugging information David Howells
2019-03-12  6:07       ` FS-Cache: Duplicate cookie detected Christian Kujau
2019-03-12  7:01       ` David Howells
2019-03-31  9:05         ` Christian Kujau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=155231585225.2992.10345384716639884052.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=anna.schumaker@netapp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lists@nerdbynature.de \
    --cc=steved@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).