Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77843C43217 for ; Thu, 20 Oct 2022 16:47:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229956AbiJTQrQ (ORCPT ); Thu, 20 Oct 2022 12:47:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230164AbiJTQrK (ORCPT ); Thu, 20 Oct 2022 12:47:10 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C359A1B65F7 for ; Thu, 20 Oct 2022 09:47:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=YlWoChLYSEMQYiEWUUCLIKlKdJHBQuxn2s43eYln8Tc=; b=PXpEM2zQcwrSU9tVsXq8D52UdG Znwgn+vT8/Iha3sQgDqeZgPMEGfME8BHdolbaAOTQEhaB7ttuRONa7Kg0zOMax2xXx1a0WFQNfQoL wLg7a9Esfyr2racEHAu5RPVkZ143MkyLMSZ+gtpnfkxJzgErvenb/Xr18+mUdjVNoZiHnOzba3Or1 mUYvzHRKM7Vb5evcKLnheLT7IUCF52uOM+UlvYbGYuIw5UC7QhNJA0jbGUfLk9wv+71UawEY6FY1y GqBAX67tMDFuB74D2qUkfBeiZYFQpC0meSZmFhNecGV9kHIFTjk7H+IFtGJnVH0qAWZK2MY6pY3Wh kS1ODYLg==; Received: from [205.220.129.26] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1olYh7-000WZp-3M; Thu, 20 Oct 2022 16:46:58 +0000 From: Christoph Hellwig To: Jens Axboe , Alasdair Kergon , Mike Snitzer Cc: Yu Kuai , dm-devel@redhat.com, linux-block@vger.kernel.org Subject: [PATCH 4/6] dm: cleanup close_table_device Date: Thu, 20 Oct 2022 09:46:03 -0700 Message-Id: <20221020164605.1764830-5-hch@lst.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221020164605.1764830-1-hch@lst.de> References: <20221020164605.1764830-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Take the list unlink and free into close_table_device so that no half torn down table_devices exist. Also remove the check for a NULL bdev as that can't happen - open_table_device never adds a table_device to the list that does not have a valid block_device. Signed-off-by: Christoph Hellwig --- drivers/md/dm.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index f60d9e8fc3abf..f592d34bd20ed 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -774,14 +774,11 @@ static struct table_device *open_table_device(struct mapped_device *md, */ static void close_table_device(struct table_device *td, struct mapped_device *md) { - if (!td->dm_dev.bdev) - return; - bd_unlink_disk_holder(td->dm_dev.bdev, dm_disk(md)); blkdev_put(td->dm_dev.bdev, td->dm_dev.mode | FMODE_EXCL); put_dax(td->dm_dev.dax_dev); - td->dm_dev.bdev = NULL; - td->dm_dev.dax_dev = NULL; + list_del(&td->list); + kfree(td); } static struct table_device *find_table_device(struct list_head *l, dev_t dev, @@ -823,11 +820,8 @@ void dm_put_table_device(struct mapped_device *md, struct dm_dev *d) struct table_device *td = container_of(d, struct table_device, dm_dev); mutex_lock(&md->table_devices_lock); - if (refcount_dec_and_test(&td->count)) { + if (refcount_dec_and_test(&td->count)) close_table_device(td, md); - list_del(&td->list); - kfree(td); - } mutex_unlock(&md->table_devices_lock); } -- 2.30.2