Commit 06064a10 authored by Dennis Dalessandro's avatar Dennis Dalessandro Committed by Roland Dreier

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.
Reviewed-by: default avatarMike Marciniszyn <mike.marciniszyn@intel.com>
Signed-off-by: default avatarDennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: default avatarRoland Dreier <roland@purestorage.com>
parent 8572de97
...@@ -130,7 +130,6 @@ void qib_set_ctxtcnt(struct qib_devdata *dd) ...@@ -130,7 +130,6 @@ void qib_set_ctxtcnt(struct qib_devdata *dd)
int qib_create_ctxts(struct qib_devdata *dd) int qib_create_ctxts(struct qib_devdata *dd)
{ {
unsigned i; unsigned i;
int ret;
int local_node_id = pcibus_to_node(dd->pcidev->bus); int local_node_id = pcibus_to_node(dd->pcidev->bus);
if (local_node_id < 0) if (local_node_id < 0)
...@@ -145,8 +144,7 @@ int qib_create_ctxts(struct qib_devdata *dd) ...@@ -145,8 +144,7 @@ int qib_create_ctxts(struct qib_devdata *dd)
if (!dd->rcd) { if (!dd->rcd) {
qib_dev_err(dd, qib_dev_err(dd,
"Unable to allocate ctxtdata array, failing\n"); "Unable to allocate ctxtdata array, failing\n");
ret = -ENOMEM; return -ENOMEM;
goto done;
} }
/* create (one or more) kctxt */ /* create (one or more) kctxt */
...@@ -163,15 +161,14 @@ int qib_create_ctxts(struct qib_devdata *dd) ...@@ -163,15 +161,14 @@ int qib_create_ctxts(struct qib_devdata *dd)
if (!rcd) { if (!rcd) {
qib_dev_err(dd, qib_dev_err(dd,
"Unable to allocate ctxtdata for Kernel ctxt, failing\n"); "Unable to allocate ctxtdata for Kernel ctxt, failing\n");
ret = -ENOMEM; kfree(dd->rcd);
goto done; dd->rcd = NULL;
return -ENOMEM;
} }
rcd->pkeys[0] = QIB_DEFAULT_P_KEY; rcd->pkeys[0] = QIB_DEFAULT_P_KEY;
rcd->seq_cnt = 1; rcd->seq_cnt = 1;
} }
ret = 0; return 0;
done:
return ret;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment