From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54DD1C2BB55 for ; Wed, 15 Apr 2020 12:27:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 26B1A21556 for ; Wed, 15 Apr 2020 12:27:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586953670; bh=qEF+NLnH7ImKjZXKW/8C3QiHyjlN7qavn8C4vwb9Qn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=nBCN0HU40Hcwo1YXj/JCA6cozn9lsN2GzDmz68bF34NOaH6uI5nF/JQwFTKF1/vAY YzSYFFOeXB1MDkbNiWbqujpGBkGDizoPPp95xstUpHiP5/r4QUjzEamG06XaxnDHOM aqdpXQGLyGpfVrxU/9DtUfhyBzJwKJfuqievSb/M= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S369289AbgDOM1s (ORCPT ); Wed, 15 Apr 2020 08:27:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:38200 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2409152AbgDOLpP (ORCPT ); Wed, 15 Apr 2020 07:45:15 -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 8322F21569; Wed, 15 Apr 2020 11:45:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586951115; bh=qEF+NLnH7ImKjZXKW/8C3QiHyjlN7qavn8C4vwb9Qn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FzzqEieY17UYVOnpRgCaj8e7WeUPJFUdr/+1eAM8QqS0hytENwSs1QLTC899/9gro oMv6EkzVyZh6oa3hqM9NYTpcatrN7qNKOztszMxMptzFKPPCe/NYgZkTUQd4srj7bF 53ulGsTI3P7Mkkf/yLzp79JxzG7Bxy9e5CUbY6Lw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Josef Bacik , Nikolay Borisov , David Sterba , Sasha Levin , linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 5.4 29/84] btrfs: handle NULL roots in btrfs_put/btrfs_grab_fs_root Date: Wed, 15 Apr 2020 07:43:46 -0400 Message-Id: <20200415114442.14166-29-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200415114442.14166-1-sashal@kernel.org> References: <20200415114442.14166-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Josef Bacik [ Upstream commit 4cdfd93002cb84471ed85b4999cd38077a317873 ] We want to use this for dropping all roots, and in some error cases we may not have a root, so handle this to make the cleanup code easier. Make btrfs_grab_fs_root the same so we can use it in cases where the root may not exist (like the quota root). Reviewed-by: Nikolay Borisov Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/disk-io.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index a6958103d87e7..ee6a75f03b551 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -97,6 +97,8 @@ struct btrfs_root *btrfs_alloc_dummy_root(struct btrfs_fs_info *fs_info); */ static inline struct btrfs_root *btrfs_grab_fs_root(struct btrfs_root *root) { + if (!root) + return NULL; if (refcount_inc_not_zero(&root->refs)) return root; return NULL; @@ -104,6 +106,8 @@ static inline struct btrfs_root *btrfs_grab_fs_root(struct btrfs_root *root) static inline void btrfs_put_fs_root(struct btrfs_root *root) { + if (!root) + return; if (refcount_dec_and_test(&root->refs)) kfree(root); } -- 2.20.1