gpu: pvr: fix error path during SGX device initialization
authorImre Deak <imre.deak@nokia.com>
Mon, 14 Mar 2011 16:12:24 +0000 (18:12 +0200)
committerGrazvydas Ignotas <notasas@gmail.com>
Sun, 20 May 2012 18:43:03 +0000 (21:43 +0300)
This also fixes some coverity reports.

Fixes: NB#233667 - Dereferencing possibly NULL pointer in sgxinit.c

Signed-off-by: Imre Deak <imre.deak@nokia.com>
pvr/sgxinit.c

index c551039..8f88052 100644 (file)
@@ -345,6 +345,8 @@ static enum PVRSRV_ERROR DevInitSGXPart1(void *pvDeviceNode)
 
        hKernelDevMemContext = BM_CreateContext(psDeviceNode, &sPDDevPAddr,
                                                NULL, NULL);
+       if (!hKernelDevMemContext)
+               goto err1;
 
        psDevInfo->sKernelPDDevPAddr = sPDDevPAddr;
 
@@ -360,6 +362,9 @@ static enum PVRSRV_ERROR DevInitSGXPart1(void *pvDeviceNode)
                                    BM_CreateHeap(hKernelDevMemContext,
                                                  &psDeviceMemoryHeap[i]);
 
+                               if (!hDevMemHeap)
+                                       goto err2;
+
                                psDeviceMemoryHeap[i].hDevMemHeap = hDevMemHeap;
                                break;
                        }
@@ -370,10 +375,28 @@ static enum PVRSRV_ERROR DevInitSGXPart1(void *pvDeviceNode)
        if (eError != PVRSRV_OK) {
                PVR_DPF(PVR_DBG_ERROR,
                         "DevInitSGX : Failed to alloc memory for BIF reset");
-               return PVRSRV_ERROR_GENERIC;
+               goto err2;
        }
 
        return PVRSRV_OK;
+err2:
+       while (i) {
+               int type;
+
+               i--;
+               type = psDeviceMemoryHeap[i].DevMemHeapType;
+               if (type != DEVICE_MEMORY_HEAP_KERNEL &&
+                   type != DEVICE_MEMORY_HEAP_SHARED &&
+                   type != DEVICE_MEMORY_HEAP_SHARED_EXPORTED)
+                       continue;
+               BM_DestroyHeap(psDeviceMemoryHeap[i].hDevMemHeap);
+       }
+       BM_DestroyContext(hKernelDevMemContext);
+err1:
+       OSFreeMem(PVRSRV_OS_NON_PAGEABLE_HEAP,
+                 sizeof(struct PVRSRV_SGXDEV_INFO), psDevInfo, NULL);
+
+       return PVRSRV_ERROR_GENERIC;
 }
 
 enum PVRSRV_ERROR SGXGetInfoForSrvinitKM(void *hDevHandle,