Return-Path: Received: from omzsmtpe01.verizonbusiness.com ([199.249.25.210]:16836 "EHLO omzsmtpe01.verizonbusiness.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751779AbdITErt (ORCPT ); Wed, 20 Sep 2017 00:47:49 -0400 From: "Levin, Alexander (Sasha Levin)" Cc: Zhu Yanjun , Joe Jin , "David S . Miller" , "Levin, Alexander (Sasha Levin)" To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" Subject: [PATCH review for 3.18 27/30] rds: ib: add error handle Date: Wed, 20 Sep 2017 04:45:56 +0000 Message-ID: <20170920044542.7571-27-alexander.levin@verizon.com> References: <20170920044542.7571-1-alexander.levin@verizon.com> In-Reply-To: <20170920044542.7571-1-alexander.levin@verizon.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Zhu Yanjun [ 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 Reviewed-by: Junxiao Bi Reviewed-by: Guanglei Li Signed-off-by: Zhu Yanjun Acked-by: Santosh Shilimkar Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/rds/ib_cm.c | 47 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c index 31b74f5e61ad..662122470bfa 100644 --- a/net/rds/ib_cm.c +++ b/net/rds/ib_cm.c @@ -298,7 +298,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn) ret =3D PTR_ERR(ic->i_send_cq); ic->i_send_cq =3D NULL; rdsdebug("ib_create_cq send failed: %d\n", ret); - goto out; + goto rds_ibdev_out; } =20 ic->i_recv_cq =3D ib_create_cq(dev, rds_ib_recv_cq_comp_handler, @@ -308,19 +308,19 @@ static int rds_ib_setup_qp(struct rds_connection *con= n) ret =3D PTR_ERR(ic->i_recv_cq); ic->i_recv_cq =3D NULL; rdsdebug("ib_create_cq recv failed: %d\n", ret); - goto out; + goto send_cq_out; } =20 ret =3D ib_req_notify_cq(ic->i_send_cq, IB_CQ_NEXT_COMP); if (ret) { rdsdebug("ib_req_notify_cq send failed: %d\n", ret); - goto out; + goto recv_cq_out; } =20 ret =3D ib_req_notify_cq(ic->i_recv_cq, IB_CQ_SOLICITED); if (ret) { rdsdebug("ib_req_notify_cq recv failed: %d\n", ret); - goto out; + goto recv_cq_out; } =20 /* XXX negotiate max send/recv with remote? */ @@ -344,7 +344,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn) ret =3D rdma_create_qp(ic->i_cm_id, ic->i_pd, &attr); if (ret) { rdsdebug("rdma_create_qp failed: %d\n", ret); - goto out; + goto recv_cq_out; } =20 ic->i_send_hdrs =3D ib_dma_alloc_coherent(dev, @@ -354,7 +354,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn) if (!ic->i_send_hdrs) { ret =3D -ENOMEM; rdsdebug("ib_dma_alloc_coherent send failed\n"); - goto out; + goto qp_out; } =20 ic->i_recv_hdrs =3D ib_dma_alloc_coherent(dev, @@ -364,7 +364,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn) if (!ic->i_recv_hdrs) { ret =3D -ENOMEM; rdsdebug("ib_dma_alloc_coherent recv failed\n"); - goto out; + goto send_hdrs_dma_out; } =20 ic->i_ack =3D ib_dma_alloc_coherent(dev, sizeof(struct rds_header), @@ -372,7 +372,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn) if (!ic->i_ack) { ret =3D -ENOMEM; rdsdebug("ib_dma_alloc_coherent ack failed\n"); - goto out; + goto recv_hdrs_dma_out; } =20 ic->i_sends =3D vzalloc_node(ic->i_send_ring.w_nr * sizeof(struct rds_ib_= send_work), @@ -380,7 +380,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn) if (!ic->i_sends) { ret =3D -ENOMEM; rdsdebug("send allocation failed\n"); - goto out; + goto ack_dma_out; } =20 ic->i_recvs =3D vzalloc_node(ic->i_recv_ring.w_nr * sizeof(struct rds_ib_= recv_work), @@ -388,7 +388,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn) if (!ic->i_recvs) { ret =3D -ENOMEM; rdsdebug("recv allocation failed\n"); - goto out; + goto sends_out; } =20 rds_ib_recv_init_ack(ic); @@ -396,8 +396,33 @@ static int rds_ib_setup_qp(struct rds_connection *conn= ) rdsdebug("conn %p pd %p mr %p cq %p %p\n", conn, ic->i_pd, ic->i_mr, ic->i_send_cq, ic->i_recv_cq); =20 -out: + return ret; + +sends_out: + vfree(ic->i_sends); +ack_dma_out: + ib_dma_free_coherent(dev, sizeof(struct rds_header), + ic->i_ack, ic->i_ack_dma); +recv_hdrs_dma_out: + ib_dma_free_coherent(dev, ic->i_recv_ring.w_nr * + sizeof(struct rds_header), + ic->i_recv_hdrs, ic->i_recv_hdrs_dma); +send_hdrs_dma_out: + ib_dma_free_coherent(dev, ic->i_send_ring.w_nr * + sizeof(struct rds_header), + ic->i_send_hdrs, ic->i_send_hdrs_dma); +qp_out: + rdma_destroy_qp(ic->i_cm_id); +recv_cq_out: + if (!ib_destroy_cq(ic->i_recv_cq)) + ic->i_recv_cq =3D NULL; +send_cq_out: + if (!ib_destroy_cq(ic->i_send_cq)) + ic->i_send_cq =3D NULL; +rds_ibdev_out: + rds_ib_remove_conn(rds_ibdev, conn); rds_ib_dev_put(rds_ibdev); + return ret; } =20 --=20 2.11.0