public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
From: Guoqing Jiang <guoqing.jiang@linux.dev>
To: haris.iqbal@ionos.com, jinpu.wang@ionos.com, jgg@ziepe.ca,
	leon@kernel.org
Cc: linux-rdma@vger.kernel.org
Subject: [PATCH RFC 04/12] RDMA/rtrs-srv: refactor the handling of failure case in map_cont_bufs
Date: Sun, 13 Nov 2022 09:08:15 +0800	[thread overview]
Message-ID: <20221113010823.6436-5-guoqing.jiang@linux.dev> (raw)
In-Reply-To: <20221113010823.6436-1-guoqing.jiang@linux.dev>

Let's call unmap_cont_bufs when failure happens, and also only update
mrs_num after everything is settled which means we can remove 'mri'.

Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev>
---
 drivers/infiniband/ulp/rtrs/rtrs-srv.c | 47 +++++++++++---------------
 1 file changed, 20 insertions(+), 27 deletions(-)

diff --git a/drivers/infiniband/ulp/rtrs/rtrs-srv.c b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
index 063082d29fc6..88eae0dcf87f 100644
--- a/drivers/infiniband/ulp/rtrs/rtrs-srv.c
+++ b/drivers/infiniband/ulp/rtrs/rtrs-srv.c
@@ -561,9 +561,11 @@ static int map_cont_bufs(struct rtrs_srv_path *srv_path)
 {
 	struct rtrs_srv_sess *srv = srv_path->srv;
 	struct rtrs_path *ss = &srv_path->s;
-	int i, mri, err, mrs_num;
+	int i, err, mrs_num;
 	unsigned int chunk_bits;
 	int chunks_per_mr = 1;
+	struct ib_mr *mr;
+	struct sg_table *sgt;
 
 	/*
 	 * Here we map queue_depth chunks to MR.  Firstly we have to
@@ -586,16 +588,14 @@ static int map_cont_bufs(struct rtrs_srv_path *srv_path)
 	if (!srv_path->mrs)
 		return -ENOMEM;
 
-	srv_path->mrs_num = mrs_num;
-
-	for (mri = 0; mri < mrs_num; mri++) {
-		struct rtrs_srv_mr *srv_mr = &srv_path->mrs[mri];
-		struct sg_table *sgt = &srv_mr->sgt;
+	for (srv_path->mrs_num = 0; srv_path->mrs_num < mrs_num;
+	     srv_path->mrs_num++) {
+		struct rtrs_srv_mr *srv_mr = &srv_path->mrs[srv_path->mrs_num];
 		struct scatterlist *s;
-		struct ib_mr *mr;
 		int nr, nr_sgt, chunks;
 
-		chunks = chunks_per_mr * mri;
+		sgt = &srv_mr->sgt;
+		chunks = chunks_per_mr * srv_path->mrs_num;
 		if (!always_invalidate)
 			chunks_per_mr = min_t(int, chunks_per_mr,
 					      srv->queue_depth - chunks);
@@ -644,31 +644,24 @@ static int map_cont_bufs(struct rtrs_srv_path *srv_path)
 
 		ib_update_fast_reg_key(mr, ib_inc_rkey(mr->rkey));
 		srv_mr->mr = mr;
-
-		continue;
-err:
-		while (mri--) {
-			srv_mr = &srv_path->mrs[mri];
-			sgt = &srv_mr->sgt;
-			mr = srv_mr->mr;
-			rtrs_iu_free(srv_mr->iu, srv_path->s.dev->ib_dev, 1);
-dereg_mr:
-			ib_dereg_mr(mr);
-unmap_sg:
-			ib_dma_unmap_sg(srv_path->s.dev->ib_dev, sgt->sgl,
-					sgt->nents, DMA_BIDIRECTIONAL);
-free_sg:
-			sg_free_table(sgt);
-		}
-		kfree(srv_path->mrs);
-
-		return err;
 	}
 
 	chunk_bits = ilog2(srv->queue_depth - 1) + 1;
 	srv_path->mem_bits = (MAX_IMM_PAYL_BITS - chunk_bits);
 
 	return 0;
+
+dereg_mr:
+	ib_dereg_mr(mr);
+unmap_sg:
+	ib_dma_unmap_sg(srv_path->s.dev->ib_dev, sgt->sgl,
+			sgt->nents, DMA_BIDIRECTIONAL);
+free_sg:
+	sg_free_table(sgt);
+err:
+	unmap_cont_bufs(srv_path);
+
+	return err;
 }
 
 static void rtrs_srv_hb_err_handler(struct rtrs_con *c)
-- 
2.31.1


  parent reply	other threads:[~2022-11-13  1:08 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-13  1:08 [PATCH RFC 00/12] Misc changes for rtrs Guoqing Jiang
2022-11-13  1:08 ` [PATCH RFC 01/12] RDMA/rtrs-srv: Remove ib_dev_count from rtrs_srv_ib_ctx Guoqing Jiang
2022-11-14  7:39   ` Jinpu Wang
2022-11-14  8:00     ` Guoqing Jiang
2022-11-14  8:24       ` Jinpu Wang
2022-11-14  8:45         ` Guoqing Jiang
2022-11-14 13:36           ` Haris Iqbal
2022-11-15 10:22             ` Guoqing Jiang
2022-11-13  1:08 ` [PATCH RFC 02/12] RDMA/rtrs-srv: Refactor rtrs_srv_rdma_cm_handler Guoqing Jiang
2022-11-14 14:39   ` Haris Iqbal
2022-11-15 10:24     ` Guoqing Jiang
2022-11-13  1:08 ` [PATCH RFC 03/12] RDMA/rtrs-srv: Only close srv_path if it is just allocated Guoqing Jiang
2022-11-14 16:18   ` Haris Iqbal
2022-11-15 10:24     ` Guoqing Jiang
2022-11-15 10:31       ` Jinpu Wang
2022-11-13  1:08 ` Guoqing Jiang [this message]
2022-11-14 16:21   ` [PATCH RFC 04/12] RDMA/rtrs-srv: refactor the handling of failure case in map_cont_bufs Haris Iqbal
2022-11-13  1:08 ` [PATCH RFC 05/12] RDMA/rtrs-srv: Correct the checking of ib_map_mr_sg Guoqing Jiang
2022-11-15 11:46   ` Jinpu Wang
2022-11-16  1:13     ` Guoqing Jiang
2022-11-16  5:44       ` Jinpu Wang
2022-11-13  1:08 ` [PATCH RFC 06/12] RDMA/rtrs-clt: " Guoqing Jiang
2022-11-15 11:49   ` Jinpu Wang
2022-11-13  1:08 ` [PATCH RFC 07/12] RDMA/rtrs-srv: Remove outdated comments from create_con Guoqing Jiang
2022-11-14 16:22   ` Haris Iqbal
2022-11-13  1:08 ` [PATCH RFC 08/12] RDMA/rtrs: Kill recon_cnt from several structs Guoqing Jiang
2022-11-15  9:39   ` Haris Iqbal
2022-11-15  9:53     ` Jinpu Wang
2022-11-15  9:58       ` Jinpu Wang
2022-11-15 10:33         ` Guoqing Jiang
2022-11-13  1:08 ` [PATCH RFC 09/12] RDMA/rtrs: Clean up rtrs_rdma_dev_pd_ops Guoqing Jiang
2022-11-15  9:18   ` Haris Iqbal
2022-11-13  1:08 ` [PATCH RFC 10/12] RDMA/rtrs-srv: Remove paths_num Guoqing Jiang
2022-11-15  9:48   ` Haris Iqbal
2022-11-15 10:01     ` Jinpu Wang
2022-11-15 10:30       ` Guoqing Jiang
2022-11-13  1:08 ` [PATCH RFC 11/12] RDMA/rtrs-srv: fix several issues in rtrs_srv_destroy_path_files Guoqing Jiang
2022-11-14 16:22   ` Haris Iqbal
2022-11-13  1:08 ` [PATCH RFC 12/12] RDMA/rtrs-srv: Remove kobject_del from rtrs_srv_destroy_once_sysfs_root_folders Guoqing Jiang
2022-11-14 16:23   ` Haris Iqbal
2022-11-14  8:32 ` [PATCH RFC 00/12] Misc changes for rtrs Leon Romanovsky
2022-11-14  8:46   ` Guoqing Jiang
2022-11-17  9:52 ` Leon Romanovsky
2022-11-17 10:06   ` Guoqing Jiang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221113010823.6436-5-guoqing.jiang@linux.dev \
    --to=guoqing.jiang@linux.dev \
    --cc=haris.iqbal@ionos.com \
    --cc=jgg@ziepe.ca \
    --cc=jinpu.wang@ionos.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox