Before calling ibv_close_device, wait for the asynchronous
processing thread to finish using the device.  This prevents
a use after free error.

Signed-off-by: Sean Hefty <[email protected]>
---
This should go into 2.2, and be pushed into the main dapl.git tree.

 trunk/ulp/dapl2/dapl/openib_cma/device.c |   12 ++++++------
 trunk/ulp/dapl2/dapl/openib_scm/device.c |   14 +++++++-------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/trunk/ulp/dapl2/dapl/openib_cma/device.c 
b/trunk/ulp/dapl2/dapl/openib_cma/device.c
index e9ec733..7ab05aa 100644
--- a/trunk/ulp/dapl2/dapl/openib_cma/device.c
+++ b/trunk/ulp/dapl2/dapl/openib_cma/device.c
@@ -474,12 +474,6 @@ DAT_RETURN dapls_ib_close_hca(IN DAPL_HCA * hca_ptr)
        dapl_dbg_log(DAPL_DBG_TYPE_UTIL, " close_hca: %p->%p\n",
                     hca_ptr, hca_ptr->ib_hca_handle);
 
-       if (hca_ptr->ib_hca_handle != IB_INVALID_HANDLE) {
-               if (rdma_destroy_id(hca_ptr->ib_trans.cm_id))
-                       return (dapl_convert_errno(errno, "ib_close_device"));
-               hca_ptr->ib_hca_handle = IB_INVALID_HANDLE;
-       }
-
        dapl_os_lock(&g_hca_lock);
        if (g_ib_thread_state != IB_THREAD_RUN) {
                dapl_os_unlock(&g_hca_lock);
@@ -508,6 +502,12 @@ DAT_RETURN dapls_ib_close_hca(IN DAPL_HCA * hca_ptr)
                dapl_os_sleep_usec(1000);
        }
 bail:
+       if (hca_ptr->ib_hca_handle != IB_INVALID_HANDLE) {
+               if (rdma_destroy_id(hca_ptr->ib_trans.cm_id))
+                       return (dapl_convert_errno(errno, "ib_close_device"));
+               hca_ptr->ib_hca_handle = IB_INVALID_HANDLE;
+       }
+
        return (DAT_SUCCESS);
 }
 
diff --git a/trunk/ulp/dapl2/dapl/openib_scm/device.c 
b/trunk/ulp/dapl2/dapl/openib_scm/device.c
index dedcb16..35d4c45 100644
--- a/trunk/ulp/dapl2/dapl/openib_scm/device.c
+++ b/trunk/ulp/dapl2/dapl/openib_scm/device.c
@@ -465,16 +465,10 @@ DAT_RETURN dapls_ib_close_hca(IN DAPL_HCA * hca_ptr)
 {
        dapl_dbg_log(DAPL_DBG_TYPE_UTIL, " close_hca: %p\n", hca_ptr);
 
-       if (hca_ptr->ib_hca_handle != IB_INVALID_HANDLE) {
-               if (ibv_close_device(hca_ptr->ib_hca_handle))
-                       return (dapl_convert_errno(errno, "ib_close_device"));
-               hca_ptr->ib_hca_handle = IB_INVALID_HANDLE;
-       }
-
        dapl_os_lock(&g_hca_lock);
        if (g_ib_thread_state != IB_THREAD_RUN) {
                dapl_os_unlock(&g_hca_lock);
-               return (DAT_SUCCESS);
+               goto out;
        }
        dapl_os_unlock(&g_hca_lock);
 
@@ -509,6 +503,12 @@ DAT_RETURN dapls_ib_close_hca(IN DAPL_HCA * hca_ptr)
                dapl_os_sleep_usec(1000);
        }
 
+out:
+       if (hca_ptr->ib_hca_handle != IB_INVALID_HANDLE) {
+               if (ibv_close_device(hca_ptr->ib_hca_handle))
+                       return (dapl_convert_errno(errno, "ib_close_device"));
+               hca_ptr->ib_hca_handle = IB_INVALID_HANDLE;
+       }
        return (DAT_SUCCESS);
 }
 



_______________________________________________
ofw mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/ofw

Reply via email to