From: Imre Deak Date: Mon, 14 Mar 2011 16:12:24 +0000 (+0200) Subject: gpu: pvr: fix error path during SGX device initialization X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=472dc29ac4eb0e07b126472a0b61ed04f58d02b3;p=sgx.git gpu: pvr: fix error path during SGX device initialization This also fixes some coverity reports. Fixes: NB#233667 - Dereferencing possibly NULL pointer in sgxinit.c Signed-off-by: Imre Deak --- diff --git a/pvr/sgxinit.c b/pvr/sgxinit.c index c551039..8f88052 100644 --- a/pvr/sgxinit.c +++ b/pvr/sgxinit.c @@ -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,