Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp994124yba; Thu, 4 Apr 2019 02:00:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqwvPR+Gnvr/tHgtF4bcFJOXKkpwjGN+lpV61FqT2QoGEXjv9wryZL0JWAqMM250C19cGqAV X-Received: by 2002:a17:902:7885:: with SMTP id q5mr5261160pll.12.1554368413175; Thu, 04 Apr 2019 02:00:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554368413; cv=none; d=google.com; s=arc-20160816; b=Y03GYEn5a0Qr/C3V1ewkgyQ0ruUVhdDye6X/a8DBTJrGqNECstqo/gpcDytvXUGf5y iQAM6Cqh4uquZSlmRJVWja0rZOI7CVZj/D982TDJ5EZ0eUJ1z+aACJhfuSReQ9rIpV3N KVSzsQa5l2TL7m48SE2FaUVWTrLKrj5z0FQ/D+MRI/SNmAtdIp9sdsmXDxCZy4vBrAf9 AjEq6mZbiabLkR4VcEcvYizv7HQnXR4x+TG2com4KsFjdKHIsKg1+nTln4yHZgPt1ztI rmrjmHYZkoph2vmMPHFTod0As66I3sN5ElGfdn4/yMEvMfR4tpsWKJPelHyKAhPdv+i6 cbDQ== 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:subject:cc:to :from:dkim-signature; bh=XA0JA+xDh8JJahtJaW0Iw5ddcDai5m3ZRqQP5ND5Tes=; b=bypPjx8kNrJAHOCPFz7HRXJj9SiY1B9qkTRoqwUyOZMqYBidFXC1TfjB3Jyh0afcRL mRjQjGlW5+3fvWLA5ndIjImx2OOBkT5HnECyU5awZ7qGuNUMFgxb3GznquSURH2pKMX7 CEBv11ZdCUy1+ZzCTqsuA8YuRshnTawVEB0PjFR8FKGyISAtwYWAe/yjYnrkF7x2m87s eoXMM6dE4CDqy1LVApiE5Tu8oxR3pMxVoVSGG1RANgLczlmwhSXVtOhCKMj6hEMg7lVp iPDZqF4YxyxckZlTF4di50HRMf35FqWEJwU1oyudobKKsfspMYoLXDgakp/QkekITPvI CIvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bViPVbAj; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n86si16285569pfb.273.2019.04.04.01.59.57; Thu, 04 Apr 2019 02:00:13 -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; dkim=pass header.i=@kernel.org header.s=default header.b=bViPVbAj; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731080AbfDDI7V (ORCPT + 99 others); Thu, 4 Apr 2019 04:59:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:35532 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730084AbfDDI7S (ORCPT ); Thu, 4 Apr 2019 04:59:18 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 62D1C2177E; Thu, 4 Apr 2019 08:59:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368357; bh=0OxmJPZnkVCDwtKNj9a///FyKDal9zhRT2X9d+2AIGw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bViPVbAjYbqchf6l7qyQa6Dcr/HRYvaXxMS5Iv8+1OiD9+ei2ulrUKOSG3V0Yi3K/ kA/tA4MW3p4wXxp/cF2eigC/32dZxi6XKK99L95IqEec/mw499/BNCh2X6XyXlo3bd BwpXt+ejpHvE3j66kIMrF48eqwAdCd1rmpy2UMt0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "zhangyi (F)" , Theodore Tso , Jan Kara , Jari Ruusu Subject: [PATCH 4.19 002/187] ext4: cleanup bh release code in ext4_ind_remove_space() Date: Thu, 4 Apr 2019 10:45:39 +0200 Message-Id: <20190404084603.221472937@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: zhangyi (F) commit 5e86bdda41534e17621d5a071b294943cae4376e upstream. Currently, we are releasing the indirect buffer where we are done with it in ext4_ind_remove_space(), so we can see the brelse() and BUFFER_TRACE() everywhere. It seems fragile and hard to read, and we may probably forget to release the buffer some day. This patch cleans up the code by putting of the code which releases the buffers to the end of the function. Signed-off-by: zhangyi (F) Signed-off-by: Theodore Ts'o Reviewed-by: Jan Kara Cc: Jari Ruusu Signed-off-by: Greg Kroah-Hartman --- fs/ext4/indirect.c | 47 ++++++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 25 deletions(-) --- a/fs/ext4/indirect.c +++ b/fs/ext4/indirect.c @@ -1219,6 +1219,7 @@ int ext4_ind_remove_space(handle_t *hand ext4_lblk_t offsets[4], offsets2[4]; Indirect chain[4], chain2[4]; Indirect *partial, *partial2; + Indirect *p = NULL, *p2 = NULL; ext4_lblk_t max_block; __le32 nr = 0, nr2 = 0; int n = 0, n2 = 0; @@ -1260,7 +1261,7 @@ int ext4_ind_remove_space(handle_t *hand } - partial = ext4_find_shared(inode, n, offsets, chain, &nr); + partial = p = ext4_find_shared(inode, n, offsets, chain, &nr); if (nr) { if (partial == chain) { /* Shared branch grows from the inode */ @@ -1285,13 +1286,11 @@ int ext4_ind_remove_space(handle_t *hand partial->p + 1, (__le32 *)partial->bh->b_data+addr_per_block, (chain+n-1) - partial); - BUFFER_TRACE(partial->bh, "call brelse"); - brelse(partial->bh); partial--; } end_range: - partial2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2); + partial2 = p2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2); if (nr2) { if (partial2 == chain2) { /* @@ -1321,16 +1320,14 @@ end_range: (__le32 *)partial2->bh->b_data, partial2->p, (chain2+n2-1) - partial2); - BUFFER_TRACE(partial2->bh, "call brelse"); - brelse(partial2->bh); partial2--; } goto do_indirects; } /* Punch happened within the same level (n == n2) */ - partial = ext4_find_shared(inode, n, offsets, chain, &nr); - partial2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2); + partial = p = ext4_find_shared(inode, n, offsets, chain, &nr); + partial2 = p2 = ext4_find_shared(inode, n2, offsets2, chain2, &nr2); /* Free top, but only if partial2 isn't its subtree. */ if (nr) { @@ -1387,15 +1384,7 @@ end_range: partial->p + 1, partial2->p, (chain+n-1) - partial); - while (partial > chain) { - BUFFER_TRACE(partial->bh, "call brelse"); - brelse(partial->bh); - } - while (partial2 > chain2) { - BUFFER_TRACE(partial2->bh, "call brelse"); - brelse(partial2->bh); - } - return 0; + goto cleanup; } /* @@ -1410,8 +1399,6 @@ end_range: partial->p + 1, (__le32 *)partial->bh->b_data+addr_per_block, (chain+n-1) - partial); - BUFFER_TRACE(partial->bh, "call brelse"); - brelse(partial->bh); partial--; } if (partial2 > chain2 && depth2 <= depth) { @@ -1419,11 +1406,21 @@ end_range: (__le32 *)partial2->bh->b_data, partial2->p, (chain2+n2-1) - partial2); - BUFFER_TRACE(partial2->bh, "call brelse"); - brelse(partial2->bh); partial2--; } } + +cleanup: + while (p && p > chain) { + BUFFER_TRACE(p->bh, "call brelse"); + brelse(p->bh); + p--; + } + while (p2 && p2 > chain2) { + BUFFER_TRACE(p2->bh, "call brelse"); + brelse(p2->bh); + p2--; + } return 0; do_indirects: @@ -1431,7 +1428,7 @@ do_indirects: switch (offsets[0]) { default: if (++n >= n2) - return 0; + break; nr = i_data[EXT4_IND_BLOCK]; if (nr) { ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 1); @@ -1439,7 +1436,7 @@ do_indirects: } case EXT4_IND_BLOCK: if (++n >= n2) - return 0; + break; nr = i_data[EXT4_DIND_BLOCK]; if (nr) { ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 2); @@ -1447,7 +1444,7 @@ do_indirects: } case EXT4_DIND_BLOCK: if (++n >= n2) - return 0; + break; nr = i_data[EXT4_TIND_BLOCK]; if (nr) { ext4_free_branches(handle, inode, NULL, &nr, &nr+1, 3); @@ -1456,5 +1453,5 @@ do_indirects: case EXT4_TIND_BLOCK: ; } - return 0; + goto cleanup; }