Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp1166600imc; Mon, 11 Mar 2019 07:51:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqzVFMfY37hfpjQUXKuBOI8NauoDcGjl/lH4ESmzJP4IAaIfYPYj+oHMyXZCy1Xs9ZQ77BXj X-Received: by 2002:a63:618d:: with SMTP id v135mr30181508pgb.238.1552315901720; Mon, 11 Mar 2019 07:51:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552315901; cv=none; d=google.com; s=arc-20160816; b=XxAbRBOsWSWQISG0j9NbWnu4KyBoFW518O2NR+C0OqX+curzmVeSQJow0MqwtmodXa j4ct8o2SH5+wVOcwJmT2gmtGrxYAMmufGYB55zVi2Sn9076CI05kTKLjVx/nzzO4KKTy uD8+WzTIRbgzhEInLqg4me5vaMML4GsPGhuGuN9mRsgQH0UOFMvevNGdHmnNjsNp02A7 tg/DsqVG0Lk6yzQpacI9BS485LkiF6pROnWi4PQX6Wuajym3gC/0C19fd5x+lUy2wTkL 3D6S5D2KOtg7/85bD+i1C3/yxoQWQRoq0qipTVJ+ow3K9bZIXlyQfQCwJ7MroXMNkbNL MFeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:cc:to:from :subject:organization; bh=0TKMtPiTNeW2Z7O8kKQXR+jxdmW1NAqsz+mD/pxBnW0=; b=BNCg8O7P9Wn+lkkCf7TsZHM6VWFVJ5IfeemRtyAIIcEvQuPu3YbX0goQHrH0t65kG1 lvShYLvAhqFpJtoh82PfVze6+X9xUQwHR41CYfp3KMZxVoOXFH4inCapE9yHg7LU/AOQ FXdvR2KknlEs5S+RQpJwjvVfFUUNDq4MpqUn7EGGP9ymUPeKGRI/jApO5J4Z42GeBl+f YmmKTswN2IC0Us2d5/9f6PXR38+M+IW93WwvObasxwi3O7k8beWSlxEx6JYfaTw/uGHk wEKeHPWHkE3gX0Hqek1hyNfzXjgbI8s25iMTYFGSAT5p0JRd4oxdQonAKXhnBqbmtAsH XwEA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r16si5086239pfd.266.2019.03.11.07.51.26; Mon, 11 Mar 2019 07:51:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727791AbfCKOuy (ORCPT + 99 others); Mon, 11 Mar 2019 10:50:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52924 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727195AbfCKOux (ORCPT ); Mon, 11 Mar 2019 10:50:53 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CC803308FE9C; Mon, 11 Mar 2019 14:50:53 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-121-148.rdu2.redhat.com [10.10.121.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id E479260C8B; Mon, 11 Mar 2019 14:50:52 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 Subject: [PATCH 2/3] fscache: Add missing unhash From: David Howells To: lists@nerdbynature.de Cc: linux-kernel@vger.kernel.org, anna.schumaker@netapp.com, steved@redhat.com, dhowells@redhat.com Date: Mon, 11 Mar 2019 14:50:52 +0000 Message-ID: <155231585225.2992.10345384716639884052.stgit@warthog.procyon.org.uk> In-Reply-To: <2827.1552315718@warthog.procyon.org.uk> References: <2827.1552315718@warthog.procyon.org.uk> User-Agent: StGit/unknown-version MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Mon, 11 Mar 2019 14:50:53 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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);