Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp853553pxk; Thu, 17 Sep 2020 19:08:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFO9uWrg2KC12zVEbw4s7yO+O1bk6qa7e9d9tVQMlOEqp2WkF0ukQjuzUfuwv/6udV26k+ X-Received: by 2002:a05:6402:489:: with SMTP id k9mr35558020edv.287.1600394922556; Thu, 17 Sep 2020 19:08:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600394922; cv=none; d=google.com; s=arc-20160816; b=xA19uI9TVrLKf6Km70x6RMb0MM5lmP0SYVTDucavLhYskvbx+tRZ7S6nnKEIA+4PNU 2tvrYfCWiqlzpWYnI8W0BEnRVS0/l8GR52mse74Fy52pfwza8yUOCRYbOD2cykI5UIMC 4lkudun89fOumOFyaOAOtV/nHdjXMffCKOUBde6xYVFtG+tUsTzDWS4VhrohAT11AiHj M7wUxuIDjFYtOC4d3GESoVF0mr9Q+M+Td9nXFt9RBSuqgQ5PwfGAghZzZmfoHr+OFMUN yFPey2h/wMiQlY04dGAv9IUHeCGtjAuN2739hlx8ahrdOkvTVBaWgH77/Coit5r/3ClO OhJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mZKMvS5lt9r7aqZ58LDJCBlM6oleQSYejCFD36MgrqY=; b=KRdAGj7pUJc/mORsgXZ4CgC3F1nvC8ORTNmJcXNuDdqzTQdvEttSMgzOmG0CZlbx38 CXKACxfHnMRmINtBHAQG9aQIlv/hBCkkU6y6J+fMhiM7LKfbkfIq06UffqMN0FtB8Dzb fnVsVd+fkCuZubrawSG8JWhdji2x8NNSBWBzMbMpJK07lNC6OQa6YVIW0XQaxB5NTFeb 5hp3qfuX4Sl1FYAMNyCY6F3NIC/CT/hhmrtI5H8Pt4i+6IJd8OXL0KiAiZK6r0jqngYY Vx3j3jZVomztzqhl3slvVuexUbYvECj9OPFESaBIZs406b7AvpiY+VyI3sShkUzQN41y 5dnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="MA/hRaJd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b14si1231320ejj.36.2020.09.17.19.08.19; Thu, 17 Sep 2020 19:08:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="MA/hRaJd"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727445AbgIRCFG (ORCPT + 99 others); Thu, 17 Sep 2020 22:05:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:52974 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727427AbgIRCFC (ORCPT ); Thu, 17 Sep 2020 22:05:02 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5255B23888; Fri, 18 Sep 2020 02:05:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394702; bh=aHxsQgvwNnbGIwSSy69r9VE0YCKcjB1WtDe7bHMU8QY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MA/hRaJda772Wog2nl3fb95K8ntJWyzHoWgBP3bm1OwYJpAUZaJY0I2fp08bzzOmu 2B3hMMhjcG1D5bYp9hAK7A9kDgNScHHe6rqv8NQoo2Hxrtl2uhPEfiN6itQei42KZU ye4h3VLSjA3Q2SepzQrM51qFPn+QodIAuZvm2D58= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Josef Bacik , David Sterba , Sasha Levin , linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 188/330] btrfs: free the reloc_control in a consistent way Date: Thu, 17 Sep 2020 21:58:48 -0400 Message-Id: <20200918020110.2063155-188-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Josef Bacik [ Upstream commit 1a0afa0ecfc4dbc8d7583d03cafd3f68f781df0c ] If we have an error while processing the reloc roots we could leak roots that were added to rc->reloc_roots before we hit the error. We could have also not removed the reloc tree mapping from our rb_tree, so clean up any remaining nodes in the reloc root rb_tree. Signed-off-by: Josef Bacik Reviewed-by: David Sterba [ use rbtree_postorder_for_each_entry_safe ] Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/relocation.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index 1313506a7ecb5..ece53d2f55ae3 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -4354,6 +4354,18 @@ static struct reloc_control *alloc_reloc_control(struct btrfs_fs_info *fs_info) return rc; } +static void free_reloc_control(struct reloc_control *rc) +{ + struct mapping_node *node, *tmp; + + free_reloc_roots(&rc->reloc_roots); + rbtree_postorder_for_each_entry_safe(node, tmp, + &rc->reloc_root_tree.rb_root, rb_node) + kfree(node); + + kfree(rc); +} + /* * Print the block group being relocated */ @@ -4486,7 +4498,7 @@ out: btrfs_dec_block_group_ro(rc->block_group); iput(rc->data_inode); btrfs_put_block_group(rc->block_group); - kfree(rc); + free_reloc_control(rc); return err; } @@ -4659,7 +4671,7 @@ out_clean: err = ret; out_unset: unset_reloc_control(rc); - kfree(rc); + free_reloc_control(rc); out: if (!list_empty(&reloc_roots)) free_reloc_roots(&reloc_roots); -- 2.25.1