Skip to content

Commit 13099ee

Browse files
Zhu Yanjungregkh
authored andcommitted
rds: ib: add error handle
[ Upstream commit 3b12f73a5c2977153f28a224392fd4729b50d1dc ] In the function rds_ib_setup_qp, the error handle is missing. When some error occurs, it is possible that memory leak occurs. As such, error handle is added. Cc: Joe Jin <joe.jin@oracle.com> Reviewed-by: Junxiao Bi <junxiao.bi@oracle.com> Reviewed-by: Guanglei Li <guanglei.li@oracle.com> Signed-off-by: Zhu Yanjun <yanjun.zhu@oracle.com> Acked-by: Santosh Shilimkar <santosh.shilimkar@oracle.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <alexander.levin@verizon.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 9bcd5ce commit 13099ee

1 file changed

Lines changed: 36 additions & 11 deletions

File tree

net/rds/ib_cm.c

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
381381
ret = PTR_ERR(ic->i_send_cq);
382382
ic->i_send_cq = NULL;
383383
rdsdebug("ib_create_cq send failed: %d\n", ret);
384-
goto out;
384+
goto rds_ibdev_out;
385385
}
386386

387387
cq_attr.cqe = ic->i_recv_ring.w_nr;
@@ -392,19 +392,19 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
392392
ret = PTR_ERR(ic->i_recv_cq);
393393
ic->i_recv_cq = NULL;
394394
rdsdebug("ib_create_cq recv failed: %d\n", ret);
395-
goto out;
395+
goto send_cq_out;
396396
}
397397

398398
ret = ib_req_notify_cq(ic->i_send_cq, IB_CQ_NEXT_COMP);
399399
if (ret) {
400400
rdsdebug("ib_req_notify_cq send failed: %d\n", ret);
401-
goto out;
401+
goto recv_cq_out;
402402
}
403403

404404
ret = ib_req_notify_cq(ic->i_recv_cq, IB_CQ_SOLICITED);
405405
if (ret) {
406406
rdsdebug("ib_req_notify_cq recv failed: %d\n", ret);
407-
goto out;
407+
goto recv_cq_out;
408408
}
409409

410410
/* XXX negotiate max send/recv with remote? */
@@ -428,7 +428,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
428428
ret = rdma_create_qp(ic->i_cm_id, ic->i_pd, &attr);
429429
if (ret) {
430430
rdsdebug("rdma_create_qp failed: %d\n", ret);
431-
goto out;
431+
goto recv_cq_out;
432432
}
433433

434434
ic->i_send_hdrs = ib_dma_alloc_coherent(dev,
@@ -438,7 +438,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
438438
if (!ic->i_send_hdrs) {
439439
ret = -ENOMEM;
440440
rdsdebug("ib_dma_alloc_coherent send failed\n");
441-
goto out;
441+
goto qp_out;
442442
}
443443

444444
ic->i_recv_hdrs = ib_dma_alloc_coherent(dev,
@@ -448,40 +448,65 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
448448
if (!ic->i_recv_hdrs) {
449449
ret = -ENOMEM;
450450
rdsdebug("ib_dma_alloc_coherent recv failed\n");
451-
goto out;
451+
goto send_hdrs_dma_out;
452452
}
453453

454454
ic->i_ack = ib_dma_alloc_coherent(dev, sizeof(struct rds_header),
455455
&ic->i_ack_dma, GFP_KERNEL);
456456
if (!ic->i_ack) {
457457
ret = -ENOMEM;
458458
rdsdebug("ib_dma_alloc_coherent ack failed\n");
459-
goto out;
459+
goto recv_hdrs_dma_out;
460460
}
461461

462462
ic->i_sends = vzalloc_node(ic->i_send_ring.w_nr * sizeof(struct rds_ib_send_work),
463463
ibdev_to_node(dev));
464464
if (!ic->i_sends) {
465465
ret = -ENOMEM;
466466
rdsdebug("send allocation failed\n");
467-
goto out;
467+
goto ack_dma_out;
468468
}
469469

470470
ic->i_recvs = vzalloc_node(ic->i_recv_ring.w_nr * sizeof(struct rds_ib_recv_work),
471471
ibdev_to_node(dev));
472472
if (!ic->i_recvs) {
473473
ret = -ENOMEM;
474474
rdsdebug("recv allocation failed\n");
475-
goto out;
475+
goto sends_out;
476476
}
477477

478478
rds_ib_recv_init_ack(ic);
479479

480480
rdsdebug("conn %p pd %p cq %p %p\n", conn, ic->i_pd,
481481
ic->i_send_cq, ic->i_recv_cq);
482482

483-
out:
483+
return ret;
484+
485+
sends_out:
486+
vfree(ic->i_sends);
487+
ack_dma_out:
488+
ib_dma_free_coherent(dev, sizeof(struct rds_header),
489+
ic->i_ack, ic->i_ack_dma);
490+
recv_hdrs_dma_out:
491+
ib_dma_free_coherent(dev, ic->i_recv_ring.w_nr *
492+
sizeof(struct rds_header),
493+
ic->i_recv_hdrs, ic->i_recv_hdrs_dma);
494+
send_hdrs_dma_out:
495+
ib_dma_free_coherent(dev, ic->i_send_ring.w_nr *
496+
sizeof(struct rds_header),
497+
ic->i_send_hdrs, ic->i_send_hdrs_dma);
498+
qp_out:
499+
rdma_destroy_qp(ic->i_cm_id);
500+
recv_cq_out:
501+
if (!ib_destroy_cq(ic->i_recv_cq))
502+
ic->i_recv_cq = NULL;
503+
send_cq_out:
504+
if (!ib_destroy_cq(ic->i_send_cq))
505+
ic->i_send_cq = NULL;
506+
rds_ibdev_out:
507+
rds_ib_remove_conn(rds_ibdev, conn);
484508
rds_ib_dev_put(rds_ibdev);
509+
485510
return ret;
486511
}
487512

0 commit comments

Comments
 (0)