Skip to contentSkip to conversation

Fix memory leak of recv context array during failed init

PATCH New Dennis Dalessandro 1 participant 2 messages Mar 17, 2014 1 message not in the archive InfiniBand

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix memory leak of recv context array during failed init

Hi Roland,

The following patch fixes a small memory leak during a failed init. It is based on change 2dea9094.

---

Dennis Dalessandro (1):
IB/qib: Fix memory leak of recv context when driver fails to initialize.

 drivers/infiniband/hw/qib/qib_init.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)
Signature · 4 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20140317180457.25881.47937.stgit-K+u1se/DcYrLESAwzcoQNrvm/[email protected]

#2 lore raw

PATCH 1/1 IB/qib: Fix memory leak of recv context when driver fails to initialize.

In qib_create_ctxts() we allocate an array to hold recv contexts. Then attempt to create data for those recv contexts. If that call to qib_create_ctxtdata() fails then an error is returned but the previously allocated memory is not freed.

---
 drivers/infiniband/hw/qib/qib_init.c |   13 +++++--------
 1 files changed, 5 insertions(+), 8 deletions(-)
drivers/infiniband/hw/qib/qib_init.c +5 -8
index 24e802f..1179a63 100644
@@ -130,7 +130,6 @@ void qib_set_ctxtcnt(struct qib_devdata *dd)
 int qib_create_ctxts(struct qib_devdata *dd)
 {
 	unsigned i;
-	int ret;
 	int local_node_id = pcibus_to_node(dd->pcidev->bus);
 
 	if (local_node_id < 0)
@@ -145,8 +144,7 @@ int qib_create_ctxts(struct qib_devdata *dd)
 	if (!dd->rcd) {
 		qib_dev_err(dd,
 			"Unable to allocate ctxtdata array, failing\n");
-		ret = -ENOMEM;
-		goto done;
+		return -ENOMEM;
 	}
 
 	/* create (one or more) kctxt */
@@ -163,15 +161,14 @@ int qib_create_ctxts(struct qib_devdata *dd)
 		if (!rcd) {
 			qib_dev_err(dd,
 				"Unable to allocate ctxtdata for Kernel ctxt, failing\n");
-			ret = -ENOMEM;
-			goto done;
+			kfree(dd->rcd);
+			dd->rcd = NULL;
+			return -ENOMEM;
 		}
 		rcd->pkeys[0] = QIB_DEFAULT_P_KEY;
 		rcd->seq_cnt = 1;
 	}
-	ret = 0;
-done:
-	return ret;
+	return 0;
 }
 
 /*

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html