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=unavailable 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 DF7D1C2BA19 for ; Wed, 15 Apr 2020 12:16:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B28B42078A for ; Wed, 15 Apr 2020 12:16:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586953010; bh=2UZ857xxFxryFMRb+KzkcCwdAD5jNdtdJqTv50+fnOo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=gWXUrMhnt5RTaM76m4WiBf+QY0LZlg0/eow6sr8uGhupzUY0i+HTnfDLOMgmB2OTE bLahtpehFbqizlsjqaVUJqDCbWN+dNCDoJ8HZ7QHK8/2qlZdcjiC6ci5Hvcm0xOJpD wFFsHqfEBi/oZM6Jb+aO54lMOnpk4oivgcBnuJ+Q= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2409801AbgDOMQq (ORCPT ); Wed, 15 Apr 2020 08:16:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:41574 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2409298AbgDOLqf (ORCPT ); Wed, 15 Apr 2020 07:46:35 -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 4FC95206A2; Wed, 15 Apr 2020 11:46:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1586951194; bh=2UZ857xxFxryFMRb+KzkcCwdAD5jNdtdJqTv50+fnOo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kKHJ+ZVVZJOv9/FPgCju9obWC7R0qOJyqmVYOe6YV4bKe9T5V81aDFR5N8LBkUnkV pCTfTLyquzdt8TXvae90dY5MN+m8t7GDqrJ3MH4OHJ7fFgVNPay1sGAKwta8NeLpNm hNyMFen7Qpx0JFGL9j/P8lOokgvU6ajV0KaEQyBU= 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 4.19 09/40] btrfs: handle NULL roots in btrfs_put/btrfs_grab_fs_root Date: Wed, 15 Apr 2020 07:45:52 -0400 Message-Id: <20200415114623.14972-9-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200415114623.14972-1-sashal@kernel.org> References: <20200415114623.14972-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 7a4a60f26dbf9..4f2d99fdf1e0c 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -100,6 +100,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; @@ -107,6 +109,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