diff mbox series

[for-rc,6/6] RDMA/hns: Improve the readability of free mr uninit

Message ID 20231129094434.134528-7-huangjunxian6@hisilicon.com (mailing list archive)
State Superseded
Delegated to: Leon Romanovsky
Headers show
Series Bugfixes and improvements for hns RoCE | expand

Commit Message

Junxian Huang Nov. 29, 2023, 9:44 a.m. UTC
From: Chengchang Tang <tangchengchang@huawei.com>

Extract uninit functions of free mr qp, cq and pd to improve
readability.

Signed-off-by: Chengchang Tang <tangchengchang@huawei.com>
Signed-off-by: Junxian Huang <huangjunxian6@hisilicon.com>
---
 drivers/infiniband/hw/hns/hns_roce_hw_v2.c | 73 ++++++++++++++--------
 1 file changed, 47 insertions(+), 26 deletions(-)

Comments

kernel test robot Dec. 6, 2023, 5:04 a.m. UTC | #1
Hi Junxian,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.7-rc4]
[cannot apply to rdma/for-next next-20231205]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Junxian-Huang/RDMA-hns-Rename-the-interrupts/20231129-183932
base:   linus/master
patch link:    https://lore.kernel.org/r/20231129094434.134528-7-huangjunxian6%40hisilicon.com
patch subject: [PATCH for-rc 6/6] RDMA/hns: Improve the readability of free mr uninit
config: sparc64-allmodconfig (https://download.01.org/0day-ci/archive/20231206/202312061253.0VL1jlNs-lkp@intel.com/config)
compiler: sparc64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231206/202312061253.0VL1jlNs-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202312061253.0VL1jlNs-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/infiniband/hw/hns/hns_roce_hw_v2.c: In function 'free_mr_exit':
>> drivers/infiniband/hw/hns/hns_roce_hw_v2.c:2684:23: warning: unused variable 'qp' [-Wunused-variable]
    2684 |         struct ib_qp *qp;
         |                       ^~


vim +/qp +2684 drivers/infiniband/hw/hns/hns_roce_hw_v2.c

  2679	
  2680	static void free_mr_exit(struct hns_roce_dev *hr_dev)
  2681	{
  2682		struct hns_roce_v2_priv *priv = hr_dev->priv;
  2683		struct hns_roce_v2_free_mr *free_mr = &priv->free_mr;
> 2684		struct ib_qp *qp;
  2685		int i;
  2686	
  2687		for (i = 0; i < ARRAY_SIZE(free_mr->rsv_qp); i++)
  2688			free_mr_uninit_qp(hr_dev, i);
  2689	
  2690		free_mr_uninit_cq(hr_dev);
  2691	
  2692		free_mr_uninit_pd(hr_dev);
  2693	}
  2694
diff mbox series

Patch

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;
 }