Fix bug where UVP would return non-NULL handle in case of failure
[mirror/winof/.git] / hw / mt23108 / user / mlnx_ual_pd.c
index 46112c8..0c5599e 100644 (file)
@@ -190,87 +190,77 @@ mlnx_post_allocate_pd (
                OUT                     ib_pd_handle_t                          *ph_uvp_pd,\r
        IN                              ci_umv_buf_t                            *p_umv_buf )\r
 {\r
-    ib_api_status_t status;\r
-    mlnx_ual_hobul_t *p_hobul = (mlnx_ual_hobul_t *)((void *)h_uvp_ca);\r
-    mlnx_ual_pd_info_t *p_new_pd;\r
+       mlnx_ual_hobul_t *p_hobul = (mlnx_ual_hobul_t *)((void *)h_uvp_ca);\r
+       mlnx_ual_pd_info_t *p_new_pd;\r
 \r
-    MT_size_t size;\r
+       MT_size_t size;\r
 \r
-    FUNC_ENTER;\r
+       FUNC_ENTER;\r
 \r
-    CL_ASSERT(p_hobul);\r
-    CL_ASSERT(p_umv_buf);\r
+       CL_ASSERT(p_hobul);\r
+       CL_ASSERT(p_umv_buf);\r
 \r
-    status = ioctl_status;\r
-    \r
-    do \r
-    {\r
        size = p_hobul->p_hca_ul_info->pd_ul_resources_sz + \r
-                     sizeof (u_int32_t) + sizeof (mlnx_ual_pd_info_t *);\r
-\r
-        cl_memcpy (&p_new_pd,\r
-                   ((u_int8_t *)p_umv_buf->p_inout_buf + size - \r
-                    sizeof (mlnx_ual_pd_info_t*)),\r
-                   sizeof (mlnx_ual_pd_info_t *));\r
-        CL_ASSERT(p_new_pd);\r
-        *ph_uvp_pd = (uvp_pd_handle_t) p_new_pd;\r
-\r
-        if (IB_SUCCESS == status)\r
-        {\r
-            if (IB_SUCCESS != p_umv_buf->status) \r
-            {\r
-                CL_TRACE (MLNX_TRACE_LVL_1, mlnx_dbg_lvl,\r
-                          ("post_allocate_pd return status %s\n", \r
-                           ib_get_err_str(p_umv_buf->status)));\r
-                status = p_umv_buf->status;\r
-                break;\r
-            }\r
-            else if ((size - sizeof (mlnx_ual_pd_info_t *)) != \r
-                     p_umv_buf->output_size )\r
-            {\r
-                CL_TRACE (MLNX_TRACE_LVL_1, mlnx_dbg_lvl,\r
-                          ("Bad user priv buffer size exp = %d, res = %ld\n",\r
-                          size, p_umv_buf->output_size));\r
-                status = IB_ERROR;\r
-                break;\r
-            }\r
+               sizeof (u_int32_t) + sizeof (mlnx_ual_pd_info_t *);\r
+\r
+       cl_memcpy (&p_new_pd,\r
+               ((u_int8_t *)p_umv_buf->p_inout_buf + size - \r
+               sizeof (mlnx_ual_pd_info_t*)),\r
+               sizeof (mlnx_ual_pd_info_t *));\r
+       CL_ASSERT(p_new_pd);\r
+       *ph_uvp_pd = (uvp_pd_handle_t) p_new_pd;\r
+\r
+       if ( ioctl_status == IB_SUCCESS )\r
+       {\r
+               if (IB_SUCCESS != p_umv_buf->status) \r
+               {\r
+                       CL_TRACE (MLNX_TRACE_LVL_1, mlnx_dbg_lvl,\r
+                               ("post_allocate_pd return status %s\n", \r
+                               ib_get_err_str(p_umv_buf->status)));\r
+                       goto err;\r
+               }\r
+               else if ((size - sizeof (mlnx_ual_pd_info_t *)) != \r
+                       p_umv_buf->output_size )\r
+               {\r
+                       CL_TRACE (MLNX_TRACE_LVL_1, mlnx_dbg_lvl,\r
+                               ("Bad user priv buffer size exp = %d, res = %ld\n",\r
+                               size, p_umv_buf->output_size));\r
+                       goto err;\r
+               }\r
 \r
-            cl_memcpy (p_new_pd->p_pd_ul_resources,\r
-                       p_umv_buf->p_inout_buf,\r
-                      p_hobul->p_hca_ul_info->pd_ul_resources_sz);\r
-            cl_memcpy (&p_new_pd->pd_idx,\r
-                       ((u_int8_t *)p_umv_buf->p_inout_buf + \r
-                        p_hobul->p_hca_ul_info->pd_ul_resources_sz),\r
-                       sizeof (u_int32_t));\r
-\r
-            if (HH_OK !=\r
-                THHUL_pdm_alloc_pd_done (p_hobul->hhul_hca_hndl,\r
-                                         p_new_pd->hhul_pd_hndl,\r
-                                         p_new_pd->pd_idx,\r
-                                         p_new_pd->p_pd_ul_resources))\r
-            {\r
-                CL_TRACE (MLNX_TRACE_LVL_1, mlnx_dbg_lvl,\r
-                          ("Call THHUL_pdm_alloc_pd_done Failed\n"));\r
-                status = IB_ERROR;\r
-                break;\r
-            }\r
-        }\r
-        else\r
-        {\r
-            if (p_new_pd->p_pd_ul_resources);\r
-            {\r
-                cl_free (p_new_pd->p_pd_ul_resources);\r
-            }\r
-            cl_free (p_new_pd);\r
-        }\r
+               cl_memcpy (p_new_pd->p_pd_ul_resources,\r
+                       p_umv_buf->p_inout_buf,\r
+                       p_hobul->p_hca_ul_info->pd_ul_resources_sz);\r
+               cl_memcpy (&p_new_pd->pd_idx,\r
+                       ((u_int8_t *)p_umv_buf->p_inout_buf + \r
+                       p_hobul->p_hca_ul_info->pd_ul_resources_sz),\r
+                       sizeof (u_int32_t));\r
+\r
+               if (HH_OK !=\r
+                       THHUL_pdm_alloc_pd_done (p_hobul->hhul_hca_hndl,\r
+                       p_new_pd->hhul_pd_hndl,\r
+                       p_new_pd->pd_idx,\r
+                       p_new_pd->p_pd_ul_resources))\r
+               {\r
+                       CL_TRACE (MLNX_TRACE_LVL_1, mlnx_dbg_lvl,\r
+                               ("Call THHUL_pdm_alloc_pd_done Failed\n"));\r
+                       goto err;\r
+               }\r
+       }\r
+       else\r
+       {\r
+err:\r
+               if (p_new_pd->p_pd_ul_resources)\r
+                       cl_free (p_new_pd->p_pd_ul_resources);\r
 \r
-    } while (0);\r
-    \r
-    cl_free (p_umv_buf->p_inout_buf);\r
+               cl_free (p_new_pd);\r
+               *ph_uvp_pd = NULL;\r
+       }\r
 \r
-    FUNC_EXIT;\r
-    return;\r
+       cl_free (p_umv_buf->p_inout_buf);\r
 \r
+       FUNC_EXIT;\r
+       return;\r
 }\r
 \r
 \r