]> git.openfabrics.org - ~ardavis/dapl.git/commitdiff
dapl: move close device after async thread is done
authorSean Hefty <sean.hefty@intel.com>
Tue, 26 Jan 2010 23:13:03 +0000 (15:13 -0800)
committerArlin Davis <arlin.r.davis@intel.com>
Tue, 26 Jan 2010 23:13:03 +0000 (15:13 -0800)
using it

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 <sean.hefty@intel.com>
dapl/openib_cma/device.c
dapl/openib_scm/device.c

index e9ec7334ab12377770a29ec77e106ee7a260d2cf..7ab05aa3fb7148dfaa8b0b12f7b7d9adbd4dc1de 100644 (file)
@@ -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);
 }
 
index dedcb16f3758d2ac8b8d5c14a4567c81c525b269..35d4c457f5c854a9ac082a4e9841d5be5c9da460 100644 (file)
@@ -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);
 }