Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp4452950rdh; Wed, 29 Nov 2023 01:48:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFJOhYtJ3KeZfp4tHTWSN3fF+GwzaidyTZB7UYuPN+5ibD8VfXyqG4sxmPRWPi6LGT5njE5 X-Received: by 2002:a17:902:e5c7:b0:1cf:a4e8:d2be with SMTP id u7-20020a170902e5c700b001cfa4e8d2bemr20716567plf.12.1701251328028; Wed, 29 Nov 2023 01:48:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701251328; cv=none; d=google.com; s=arc-20160816; b=nPYPF2yd05wCtjOi4Dt0MeYkQoyMTzvyECOcY4X17v68zmtsy95v4xWz1WSR94uZ9t BI3cRNyrbLCCsiRmuFHbsYN/sTafeOB6tIso1EcXhzPDfAKJCxu39ilKU1GQ9S/5q4tj ybzEXA2q/g4l4dXJcTQzNyY55r/ZYQqRoMoq9KaEo3dvFwU37ME35YI//C9Kc24p/JVG bJhu4vRW6590mjswOAZACijLxGzLELFUM+yzliESoQbYUx1kUkvFrhe1H7WVtpcEYLQy 6NcSQHydJ/MLJZS1z1KHp6nYr1SScdxGXV/DlUdaui+9gL70iLXNS29mSC30nbNBY9PX 3bPw== 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; bh=0d3BOyTzUZEI5X0+/fp24DMujKau3vF7VHTOu9dDR/k=; fh=KWvyQxL3Ff+3WPSMjlYu+P4255AmcMULAsFol6M1vNI=; b=CIrbpwb47dxIRlLfh384Yyo1eoVrgKHt+XMPzAgDe4vvaW0pfdW50lOdTbxl+M3dwZ YAiI0aVb8s4dCZ86SSbNlilbJjTM++KyBezHVQV4eEWk+oihrFuoDkg5+I15DnHMKwtM NvOVlO+lFU4vC1xbOz8kXu0xMeCgxIb46MHN2X8ygW+wFoeEylgTPbO5oV6/RrDuPWNq 1U7dS7K6iTd3F5ejG6gP16oRVVxGwMWRzt8R7U9wJHJ3bbBz+074857BbS+O4ENxgy5o nOh2J/s7e9+M8ki6n+A1rg+ZwyJSJHFtx0y9IvFnq9njLka7+zG3TxuhH0STgYgI2pwA gdQg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id d16-20020a170903231000b001cfd934bda1si5437563plh.232.2023.11.29.01.48.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Nov 2023 01:48:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=hisilicon.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 52ED68031E25; Wed, 29 Nov 2023 01:48:45 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231160AbjK2Jsb (ORCPT + 99 others); Wed, 29 Nov 2023 04:48:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229974AbjK2JsG (ORCPT ); Wed, 29 Nov 2023 04:48:06 -0500 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C719719BC; Wed, 29 Nov 2023 01:48:11 -0800 (PST) Received: from kwepemi500006.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SgDsL5CSTzMnVg; Wed, 29 Nov 2023 17:43:18 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemi500006.china.huawei.com (7.221.188.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 29 Nov 2023 17:48:09 +0800 From: Junxian Huang To: , CC: , , , Subject: [PATCH for-rc 6/6] RDMA/hns: Improve the readability of free mr uninit Date: Wed, 29 Nov 2023 17:44:34 +0800 Message-ID: <20231129094434.134528-7-huangjunxian6@hisilicon.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231129094434.134528-1-huangjunxian6@hisilicon.com> References: <20231129094434.134528-1-huangjunxian6@hisilicon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500006.china.huawei.com (7.221.188.68) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 29 Nov 2023 01:48:46 -0800 (PST) From: Chengchang Tang Extract uninit functions of free mr qp, cq and pd to improve readability. Signed-off-by: Chengchang Tang Signed-off-by: Junxian Huang --- drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 73 ++++++++++++++-------- 1 file changed, 47 insertions(+), 26 deletions(-) diff --git a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c index 538f3e8949fc..be02034a8818 100644 --- a/drivers/infiniband/hw/hns/hns_roce_hw_v2.c +++ b/drivers/infiniband/hw/hns/hns_roce_hw_v2.c @@ -2573,6 +2573,19 @@ static struct ib_pd *free_mr_init_pd(struct hns_roce_dev *hr_dev) return pd; } +static void free_mr_uninit_pd(struct hns_roce_dev *hr_dev) +{ + struct hns_roce_v2_priv *priv = hr_dev->priv; + struct hns_roce_v2_free_mr *free_mr = &priv->free_mr; + + if (!free_mr->rsv_pd) + return; + + hns_roce_dealloc_pd(&free_mr->rsv_pd->ibpd, NULL); + kfree(free_mr->rsv_pd); + free_mr->rsv_pd = NULL; +} + static struct ib_cq *free_mr_init_cq(struct hns_roce_dev *hr_dev) { struct hns_roce_v2_priv *priv = hr_dev->priv; @@ -2607,6 +2620,19 @@ static struct ib_cq *free_mr_init_cq(struct hns_roce_dev *hr_dev) return cq; } +static void free_mr_uninit_cq(struct hns_roce_dev *hr_dev) +{ + struct hns_roce_v2_priv *priv = hr_dev->priv; + struct hns_roce_v2_free_mr *free_mr = &priv->free_mr; + + if (!free_mr->rsv_cq) + return; + + hns_roce_destroy_cq(&free_mr->rsv_cq->ib_cq, NULL); + kfree(free_mr->rsv_cq); + free_mr->rsv_cq = NULL; +} + static int free_mr_init_qp(struct hns_roce_dev *hr_dev, struct ib_cq *cq, struct ib_qp_init_attr *init_attr, int i) { @@ -2638,6 +2664,19 @@ static int free_mr_init_qp(struct hns_roce_dev *hr_dev, struct ib_cq *cq, return 0; } +static void free_mr_uninit_qp(struct hns_roce_dev *hr_dev, int i) +{ + struct hns_roce_v2_priv *priv = hr_dev->priv; + struct hns_roce_v2_free_mr *free_mr = &priv->free_mr; + + if (!free_mr->rsv_qp[i]) + return; + + hns_roce_v2_destroy_qp(&free_mr->rsv_qp[i]->ibqp, NULL); + kfree(free_mr->rsv_qp[i]); + free_mr->rsv_qp[i] = NULL; +} + static void free_mr_exit(struct hns_roce_dev *hr_dev) { struct hns_roce_v2_priv *priv = hr_dev->priv; @@ -2645,26 +2684,12 @@ static void free_mr_exit(struct hns_roce_dev *hr_dev) struct ib_qp *qp; int i; - for (i = 0; i < ARRAY_SIZE(free_mr->rsv_qp); i++) { - if (free_mr->rsv_qp[i]) { - qp = &free_mr->rsv_qp[i]->ibqp; - hns_roce_v2_destroy_qp(qp, NULL); - kfree(free_mr->rsv_qp[i]); - free_mr->rsv_qp[i] = NULL; - } - } + for (i = 0; i < ARRAY_SIZE(free_mr->rsv_qp); i++) + free_mr_uninit_qp(hr_dev, i); - if (free_mr->rsv_cq) { - hns_roce_destroy_cq(&free_mr->rsv_cq->ib_cq, NULL); - kfree(free_mr->rsv_cq); - free_mr->rsv_cq = NULL; - } + free_mr_uninit_cq(hr_dev); - if (free_mr->rsv_pd) { - hns_roce_dealloc_pd(&free_mr->rsv_pd->ibpd, NULL); - kfree(free_mr->rsv_pd); - free_mr->rsv_pd = NULL; - } + free_mr_uninit_pd(hr_dev); } static int free_mr_alloc_res(struct hns_roce_dev *hr_dev) @@ -2705,16 +2730,12 @@ static int free_mr_alloc_res(struct hns_roce_dev *hr_dev) return 0; create_failed_qp: - for (i--; i >= 0; i--) { - hns_roce_v2_destroy_qp(&free_mr->rsv_qp[i]->ibqp, NULL); - kfree(free_mr->rsv_qp[i]); - } - hns_roce_destroy_cq(cq, NULL); - kfree(cq); + for (i--; i >= 0; i--) + free_mr_uninit_qp(hr_dev, i); + free_mr_uninit_cq(hr_dev); create_failed_cq: - hns_roce_dealloc_pd(pd, NULL); - kfree(pd); + free_mr_uninit_pd(hr_dev); return ret; } -- 2.30.0