mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>
Cc: Zhu Yanjun <yanjun.zhu@oracle.com>, Joe Jin <joe.jin@oracle.com>,
	"David S . Miller" <davem@davemloft.net>,
	"Levin, Alexander (Sasha Levin)" <alexander.levin@verizon.com>
Subject: [PATCH for 4.9 31/39] rds: ib: add error handle
Date: Mon, 18 Sep 2017 00:40:34 +0000	[thread overview]
Message-ID: <20170918004024.7247-14-alexander.levin@verizon.com> (raw)
In-Reply-To: <20170918004024.7247-1-alexander.levin@verizon.com>

From: Zhu Yanjun <yanjun.zhu@oracle.com>

[ 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>
---
 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 5b2ab95afa07..169156cfd4c8 100644
--- a/net/rds/ib_cm.c
+++ b/net/rds/ib_cm.c
@@ -405,7 +405,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
 		ret = PTR_ERR(ic->i_send_cq);
 		ic->i_send_cq = NULL;
 		rdsdebug("ib_create_cq send failed: %d\n", ret);
-		goto out;
+		goto rds_ibdev_out;
 	}
 
 	cq_attr.cqe = ic->i_recv_ring.w_nr;
@@ -416,19 +416,19 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
 		ret = PTR_ERR(ic->i_recv_cq);
 		ic->i_recv_cq = NULL;
 		rdsdebug("ib_create_cq recv failed: %d\n", ret);
-		goto out;
+		goto send_cq_out;
 	}
 
 	ret = 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;
 	}
 
 	ret = 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;
 	}
 
 	/* XXX negotiate max send/recv with remote? */
@@ -453,7 +453,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
 	ret = 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;
 	}
 
 	ic->i_send_hdrs = ib_dma_alloc_coherent(dev,
@@ -463,7 +463,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
 	if (!ic->i_send_hdrs) {
 		ret = -ENOMEM;
 		rdsdebug("ib_dma_alloc_coherent send failed\n");
-		goto out;
+		goto qp_out;
 	}
 
 	ic->i_recv_hdrs = ib_dma_alloc_coherent(dev,
@@ -473,7 +473,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
 	if (!ic->i_recv_hdrs) {
 		ret = -ENOMEM;
 		rdsdebug("ib_dma_alloc_coherent recv failed\n");
-		goto out;
+		goto send_hdrs_dma_out;
 	}
 
 	ic->i_ack = ib_dma_alloc_coherent(dev, sizeof(struct rds_header),
@@ -481,7 +481,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
 	if (!ic->i_ack) {
 		ret = -ENOMEM;
 		rdsdebug("ib_dma_alloc_coherent ack failed\n");
-		goto out;
+		goto recv_hdrs_dma_out;
 	}
 
 	ic->i_sends = vzalloc_node(ic->i_send_ring.w_nr * sizeof(struct rds_ib_send_work),
@@ -489,7 +489,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
 	if (!ic->i_sends) {
 		ret = -ENOMEM;
 		rdsdebug("send allocation failed\n");
-		goto out;
+		goto ack_dma_out;
 	}
 
 	ic->i_recvs = vzalloc_node(ic->i_recv_ring.w_nr * sizeof(struct rds_ib_recv_work),
@@ -497,7 +497,7 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
 	if (!ic->i_recvs) {
 		ret = -ENOMEM;
 		rdsdebug("recv allocation failed\n");
-		goto out;
+		goto sends_out;
 	}
 
 	rds_ib_recv_init_ack(ic);
@@ -505,8 +505,33 @@ static int rds_ib_setup_qp(struct rds_connection *conn)
 	rdsdebug("conn %p pd %p cq %p %p\n", conn, ic->i_pd,
 		 ic->i_send_cq, ic->i_recv_cq);
 
-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 = NULL;
+send_cq_out:
+	if (!ib_destroy_cq(ic->i_send_cq))
+		ic->i_send_cq = NULL;
+rds_ibdev_out:
+	rds_ib_remove_conn(rds_ibdev, conn);
 	rds_ib_dev_put(rds_ibdev);
+
 	return ret;
 }
 
-- 
2.11.0

  parent reply	other threads:[~2017-09-18  0:42 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-18  0:40 [PATCH for 4.9 18/39] iommu/exynos: Block SYSMMU while invalidating FLPD cache Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 19/39] [media] exynos-gsc: Do not swap cb/cr for semi planar formats Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 20/39] MIPS: smp-cps: Fix retrieval of VPE mask on big endian CPUs Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 23/39] parisc: perf: Fix potential NULL pointer dereference Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 21/39] nvme-rdma: handle cpu unplug when re-establishing the controller Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 22/39] netfilter: nfnl_cthelper: fix incorrect helper->expect_class_max Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 27/39] x86/acpi: Restore the order of CPU IDs Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 26/39] cpufreq: intel_pstate: Update pid_params.sample_rate_ns in pid_param_set() Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 25/39] ibmvnic: Free tx/rx scrq pointer array when releasing sub-crqs Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 24/39] nfs: make nfs4_cb_sv_ops static Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 29/39] arm64: kasan: avoid bad virt_to_pfn() Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 30/39] mm/cgroup: avoid panic when init with low memory Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 28/39] iommu/io-pgtable-arm: Check for leaf entry before dereferencing it Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` Levin, Alexander (Sasha Levin) [this message]
2017-09-18  0:40 ` [PATCH for 4.9 35/39] xfs: remove kmem_zalloc_greedy Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 33/39] netfilter: nf_tables: set pktinfo->thoff at AH header if found Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 32/39] md/raid10: submit bio directly to replacement disk Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 34/39] i2c: meson: fix wrong variable usage in meson_i2c_put_data Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 38/39] ARM: dts: BCM5301X: Fix memory start address Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 36/39] ASoC: wm_adsp: Return an error on write to a disabled volatile control Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 37/39] libata: transport: Remove circular dependency at free time Levin, Alexander (Sasha Levin)
2017-09-18  0:40 ` [PATCH for 4.9 39/39] tools/power turbostat: bugfix: GFXMHz column not changing Levin, Alexander (Sasha Levin)

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=20170918004024.7247-14-alexander.levin@verizon.com \
    --to=alexander.levin@verizon.com \
    --cc=davem@davemloft.net \
    --cc=joe.jin@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=yanjun.zhu@oracle.com \
    /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

all inboxes | Powered by JetHome®