net/qede/base: add error handling for mutex allocation
authorRasesh Mody <rasesh.mody@cavium.com>
Sat, 29 Sep 2018 08:14:31 +0000 (08:14 +0000)
committerFerruh Yigit <ferruh.yigit@intel.com>
Thu, 11 Oct 2018 16:53:48 +0000 (18:53 +0200)
Add error handling for mutex allocation failure

Signed-off-by: Rasesh Mody <rasesh.mody@cavium.com>
drivers/net/qede/base/ecore_cxt.c
drivers/net/qede/base/ecore_vf.c

index bf36ce5..6bc6348 100644 (file)
@@ -1133,6 +1133,9 @@ enum _ecore_status_t ecore_cxt_mngr_alloc(struct ecore_hwfn *p_hwfn)
                return ECORE_NOMEM;
        }
 
+       /* Set the cxt mangr pointer prior to further allocations */
+       p_hwfn->p_cxt_mngr = p_mngr;
+
        /* Initialize ILT client registers */
        clients = p_mngr->clients;
        clients[ILT_CLI_CDUC].first.reg = ILT_CFG_REG(CDUC, FIRST_ILT);
@@ -1174,13 +1177,13 @@ enum _ecore_status_t ecore_cxt_mngr_alloc(struct ecore_hwfn *p_hwfn)
 
        /* Initialize the dynamic ILT allocation mutex */
 #ifdef CONFIG_ECORE_LOCK_ALLOC
-       OSAL_MUTEX_ALLOC(p_hwfn, &p_mngr->mutex);
+       if (OSAL_MUTEX_ALLOC(p_hwfn, &p_mngr->mutex)) {
+               DP_NOTICE(p_hwfn, false, "Failed to alloc p_mngr->mutex\n");
+               return ECORE_NOMEM;
+       }
 #endif
        OSAL_MUTEX_INIT(&p_mngr->mutex);
 
-       /* Set the cxt mangr pointer priori to further allocations */
-       p_hwfn->p_cxt_mngr = p_mngr;
-
        return ECORE_SUCCESS;
 }
 
index d2213f7..409b301 100644 (file)
@@ -565,13 +565,20 @@ enum _ecore_status_t ecore_vf_hw_prepare(struct ecore_hwfn *p_hwfn)
                                                           phys,
                                                           p_iov->bulletin.
                                                           size);
+       if (!p_iov->bulletin.p_virt) {
+               DP_NOTICE(p_hwfn, false, "Failed to alloc bulletin memory\n");
+               goto free_pf2vf_reply;
+       }
        DP_VERBOSE(p_hwfn, ECORE_MSG_IOV,
                   "VF's bulletin Board [%p virt 0x%lx phys 0x%08x bytes]\n",
                   p_iov->bulletin.p_virt, (unsigned long)p_iov->bulletin.phys,
                   p_iov->bulletin.size);
 
 #ifdef CONFIG_ECORE_LOCK_ALLOC
-       OSAL_MUTEX_ALLOC(p_hwfn, &p_iov->mutex);
+       if (OSAL_MUTEX_ALLOC(p_hwfn, &p_iov->mutex)) {
+               DP_NOTICE(p_hwfn, false, "Failed to allocate p_iov->mutex\n");
+               goto free_bulletin_mem;
+       }
 #endif
        OSAL_MUTEX_INIT(&p_iov->mutex);
 
@@ -609,6 +616,16 @@ enum _ecore_status_t ecore_vf_hw_prepare(struct ecore_hwfn *p_hwfn)
 
        return rc;
 
+#ifdef CONFIG_ECORE_LOCK_ALLOC
+free_bulletin_mem:
+       OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev, p_iov->bulletin.p_virt,
+                              p_iov->bulletin.phys,
+                              p_iov->bulletin.size);
+#endif
+free_pf2vf_reply:
+       OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev, p_iov->pf2vf_reply,
+                              p_iov->pf2vf_reply_phys,
+                              sizeof(union pfvf_tlvs));
 free_vf2pf_request:
        OSAL_DMA_FREE_COHERENT(p_hwfn->p_dev, p_iov->vf2pf_request,
                               p_iov->vf2pf_request_phys,