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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A394FC32793 for ; Wed, 18 Jan 2023 13:47:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230045AbjARNrD (ORCPT ); Wed, 18 Jan 2023 08:47:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230493AbjARNqh (ORCPT ); Wed, 18 Jan 2023 08:46:37 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD21830B28 for ; Wed, 18 Jan 2023 05:16:44 -0800 (PST) Received: from dggpeml500025.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NxmSn0FNRzRrff; Wed, 18 Jan 2023 21:14:49 +0800 (CST) Received: from [10.174.176.117] (10.174.176.117) by dggpeml500025.china.huawei.com (7.185.36.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 18 Jan 2023 21:16:41 +0800 Subject: Re: [dm-devel] [PATCH] dm: remove unnecessary check when using dm_get_mdptr() To: Hou Tao , CC: Mike Snitzer , , Alasdair Kergon References: <20221216042353.3132139-1-houtao@huaweicloud.com> From: Hou Tao Message-ID: Date: Wed, 18 Jan 2023 21:16:41 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20221216042353.3132139-1-houtao@huaweicloud.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.174.176.117] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpeml500025.china.huawei.com (7.185.36.35) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ping ? On 12/16/2022 12:23 PM, Hou Tao wrote: > From: Hou Tao > > __hash_remove() removes hash_cell with _hash_lock locked, so acquiring > _hash_lock can guarantee no-NULL hc returned from dm_get_mdptr() must > have not been removed and hc->md must still be md. > > __hash_remove() also acquires dm_hash_cells_mutex before setting mdptr > as NULL, so in dm_copy_name_and_uuid() after acquiring > dm_hash_cells_mutex and ensuring returned hc is not NULL, the returned > hc must still be alive and hc->md must still be md. > > So removing these unnecessary hc->md != md checks when using > dm_get_mdptr() with _hash_lock or dm_hash_cells_mutex acquired. > > Signed-off-by: Hou Tao > --- > drivers/md/dm-ioctl.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c > index 3bfc1583c20a..2a86524661d1 100644 > --- a/drivers/md/dm-ioctl.c > +++ b/drivers/md/dm-ioctl.c > @@ -772,7 +772,7 @@ static struct dm_table *dm_get_inactive_table(struct mapped_device *md, int *src > > down_read(&_hash_lock); > hc = dm_get_mdptr(md); > - if (!hc || hc->md != md) { > + if (!hc) { > DMERR("device has been removed from the dev hash table."); > goto out; > } > @@ -1476,7 +1476,7 @@ static int table_load(struct file *filp, struct dm_ioctl *param, size_t param_si > /* stage inactive table */ > down_write(&_hash_lock); > hc = dm_get_mdptr(md); > - if (!hc || hc->md != md) { > + if (!hc) { > DMERR("device has been removed from the dev hash table."); > up_write(&_hash_lock); > r = -ENXIO; > @@ -2128,7 +2128,7 @@ int dm_copy_name_and_uuid(struct mapped_device *md, char *name, char *uuid) > > mutex_lock(&dm_hash_cells_mutex); > hc = dm_get_mdptr(md); > - if (!hc || hc->md != md) { > + if (!hc) { > r = -ENXIO; > goto out; > }