Skip to content
/ linux Public

Commit acb9ee3

Browse files
Guoqing JiangSasha Levin
authored andcommitted
RDMA/rtrs-srv: Refactor the handling of failure case in map_cont_bufs
[ Upstream commit 0f597ac ] 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'. Acked-by: Md Haris Iqbal <haris.iqbal@ionos.com> Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev> Link: https://lore.kernel.org/r/20221117101945.6317-3-guoqing.jiang@linux.dev Signed-off-by: Leon Romanovsky <leon@kernel.org> Stable-dep-of: 83835f7 ("RDMA/rtrs-srv: fix SG mapping") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 9b7d77c commit acb9ee3

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

drivers/infiniband/ulp/rtrs/rtrs-srv.c

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,11 @@ static int map_cont_bufs(struct rtrs_srv_path *srv_path)
559559
{
560560
struct rtrs_srv_sess *srv = srv_path->srv;
561561
struct rtrs_path *ss = &srv_path->s;
562-
int i, mri, err, mrs_num;
562+
int i, err, mrs_num;
563563
unsigned int chunk_bits;
564564
int chunks_per_mr = 1;
565+
struct ib_mr *mr;
566+
struct sg_table *sgt;
565567

566568
/*
567569
* Here we map queue_depth chunks to MR. Firstly we have to
@@ -584,16 +586,14 @@ static int map_cont_bufs(struct rtrs_srv_path *srv_path)
584586
if (!srv_path->mrs)
585587
return -ENOMEM;
586588

587-
srv_path->mrs_num = mrs_num;
588-
589-
for (mri = 0; mri < mrs_num; mri++) {
590-
struct rtrs_srv_mr *srv_mr = &srv_path->mrs[mri];
591-
struct sg_table *sgt = &srv_mr->sgt;
589+
for (srv_path->mrs_num = 0; srv_path->mrs_num < mrs_num;
590+
srv_path->mrs_num++) {
591+
struct rtrs_srv_mr *srv_mr = &srv_path->mrs[srv_path->mrs_num];
592592
struct scatterlist *s;
593-
struct ib_mr *mr;
594593
int nr, nr_sgt, chunks;
595594

596-
chunks = chunks_per_mr * mri;
595+
sgt = &srv_mr->sgt;
596+
chunks = chunks_per_mr * srv_path->mrs_num;
597597
if (!always_invalidate)
598598
chunks_per_mr = min_t(int, chunks_per_mr,
599599
srv->queue_depth - chunks);
@@ -642,31 +642,24 @@ static int map_cont_bufs(struct rtrs_srv_path *srv_path)
642642

643643
ib_update_fast_reg_key(mr, ib_inc_rkey(mr->rkey));
644644
srv_mr->mr = mr;
645-
646-
continue;
647-
err:
648-
while (mri--) {
649-
srv_mr = &srv_path->mrs[mri];
650-
sgt = &srv_mr->sgt;
651-
mr = srv_mr->mr;
652-
rtrs_iu_free(srv_mr->iu, srv_path->s.dev->ib_dev, 1);
653-
dereg_mr:
654-
ib_dereg_mr(mr);
655-
unmap_sg:
656-
ib_dma_unmap_sg(srv_path->s.dev->ib_dev, sgt->sgl,
657-
sgt->nents, DMA_BIDIRECTIONAL);
658-
free_sg:
659-
sg_free_table(sgt);
660-
}
661-
kfree(srv_path->mrs);
662-
663-
return err;
664645
}
665646

666647
chunk_bits = ilog2(srv->queue_depth - 1) + 1;
667648
srv_path->mem_bits = (MAX_IMM_PAYL_BITS - chunk_bits);
668649

669650
return 0;
651+
652+
dereg_mr:
653+
ib_dereg_mr(mr);
654+
unmap_sg:
655+
ib_dma_unmap_sg(srv_path->s.dev->ib_dev, sgt->sgl,
656+
sgt->nents, DMA_BIDIRECTIONAL);
657+
free_sg:
658+
sg_free_table(sgt);
659+
err:
660+
unmap_cont_bufs(srv_path);
661+
662+
return err;
670663
}
671664

672665
static void rtrs_srv_hb_err_handler(struct rtrs_con *c)

0 commit comments

Comments
 (0)