summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAngela Stegmaier2018-04-03 14:19:04 -0500
committerPraneeth Bajjuri2018-04-18 10:37:28 -0500
commitb93f79c32d6ab61cccbe0d1fe26076ff8481ba1a (patch)
treefc9917b1838f87a71aae2f948a7005126ec2c16b
parentea2ca3314cad848237d99a089caa54fcd9764ed5 (diff)
downloadandroid-hardware-ti-dra7xx-b93f79c32d6ab61cccbe0d1fe26076ff8481ba1a.tar.gz
android-hardware-ti-dra7xx-b93f79c32d6ab61cccbe0d1fe26076ff8481ba1a.tar.xz
android-hardware-ti-dra7xx-b93f79c32d6ab61cccbe0d1fe26076ff8481ba1a.zip
OMX: Base: Add Protection For Alloc/Use During Error Cleanup
If Port Enable fails during port reconfig (in VIDDEC3_create or if all buffers don't come in time), error handling will automatically disable the port and cleanup resources. If the application is still calling AllocateBuffer during this time, then it was possible that a crash may happen when AllocateBuffer uses the same resources that are being released during Disable transition. To prevent this race condition, a mutex is added around Allocate/Use_Buffer and the error handling for the failure case. Change-Id: Ief3f999c4c04ab5dc2ae2b3cdbd8be357e18903d Signed-off-by: Angela Stegmaier <angelabaker@ti.com>
-rw-r--r--omx/base/omx_base_comp/inc/omx_base_internal.h1
-rw-r--r--omx/base/omx_base_comp/src/omx_base.c12
-rw-r--r--omx/base/omx_base_comp/src/omx_base_internal.c13
3 files changed, 26 insertions, 0 deletions
diff --git a/omx/base/omx_base_comp/inc/omx_base_internal.h b/omx/base/omx_base_comp/inc/omx_base_internal.h
index ad1f171..f989ae9 100644
--- a/omx/base/omx_base_comp/inc/omx_base_internal.h
+++ b/omx/base/omx_base_comp/inc/omx_base_internal.h
@@ -95,6 +95,7 @@ typedef struct OMXBaseComp_Private {
95 OMX_PTR pErrorCmdcompleteEvent; 95 OMX_PTR pErrorCmdcompleteEvent;
96 OMX_PTR pCmdPipeMutex; 96 OMX_PTR pCmdPipeMutex;
97 OMX_PTR pNewStateMutex; 97 OMX_PTR pNewStateMutex;
98 OMX_PTR pPortDisableMutex;
98 OMX_ERRORTYPE (*fpInvokeProcessFunction)(OMX_HANDLETYPE hComponent, 99 OMX_ERRORTYPE (*fpInvokeProcessFunction)(OMX_HANDLETYPE hComponent,
99 OMX_U32 retEvent); 100 OMX_U32 retEvent);
100 101
diff --git a/omx/base/omx_base_comp/src/omx_base.c b/omx/base/omx_base_comp/src/omx_base.c
index 931bef8..31079bf 100644
--- a/omx/base/omx_base_comp/src/omx_base.c
+++ b/omx/base/omx_base_comp/src/omx_base.c
@@ -739,6 +739,9 @@ OMX_ERRORTYPE OMXBase_AllocateBuffer(OMX_HANDLETYPE hComponent,
739 pComp = (OMX_COMPONENTTYPE *)hComponent; 739 pComp = (OMX_COMPONENTTYPE *)hComponent;
740 pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; 740 pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate;
741 pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; 741 pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData;
742
743 OSAL_ObtainMutex(pBaseCompPvt->pPortDisableMutex, OSAL_SUSPEND);
744
742 nStartPortNumber = pBaseComp->nMinStartPortIndex; 745 nStartPortNumber = pBaseComp->nMinStartPortIndex;
743 nPorts = pBaseComp->nNumPorts; 746 nPorts = pBaseComp->nNumPorts;
744 OMX_CHECK(nPortIndex >= nStartPortNumber && nPortIndex < nPorts, 747 OMX_CHECK(nPortIndex >= nStartPortNumber && nPortIndex < nPorts,
@@ -811,6 +814,9 @@ OMX_ERRORTYPE OMXBase_AllocateBuffer(OMX_HANDLETYPE hComponent,
811 } 814 }
812 815
813EXIT: 816EXIT:
817 if ((hComponent != NULL) && (nSizeBytes > 0)) {
818 OSAL_ReleaseMutex(pBaseCompPvt->pPortDisableMutex);
819 }
814 return (eError); 820 return (eError);
815} 821}
816 822
@@ -839,6 +845,9 @@ OMX_ERRORTYPE OMXBase_UseBuffer(OMX_HANDLETYPE hComponent,
839 pComp = (OMX_COMPONENTTYPE *)hComponent; 845 pComp = (OMX_COMPONENTTYPE *)hComponent;
840 pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; 846 pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate;
841 pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; 847 pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData;
848
849 OSAL_ObtainMutex(pBaseCompPvt->pPortDisableMutex, OSAL_SUSPEND);
850
842 nStartPortNumber = pBaseComp->nMinStartPortIndex; 851 nStartPortNumber = pBaseComp->nMinStartPortIndex;
843 nPorts = pBaseComp->nNumPorts; 852 nPorts = pBaseComp->nNumPorts;
844 OMX_CHECK(nPortIndex >= nStartPortNumber && nPortIndex < nPorts, 853 OMX_CHECK(nPortIndex >= nStartPortNumber && nPortIndex < nPorts,
@@ -914,6 +923,9 @@ OMX_ERRORTYPE OMXBase_UseBuffer(OMX_HANDLETYPE hComponent,
914 OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); 923 OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources);
915 } 924 }
916EXIT: 925EXIT:
926 if (hComponent != NULL) {
927 OSAL_ReleaseMutex(pBaseCompPvt->pPortDisableMutex);
928 }
917 return (eError); 929 return (eError);
918} 930}
919 931
diff --git a/omx/base/omx_base_comp/src/omx_base_internal.c b/omx/base/omx_base_comp/src/omx_base_internal.c
index 953361d..a575491 100644
--- a/omx/base/omx_base_comp/src/omx_base_internal.c
+++ b/omx/base/omx_base_comp/src/omx_base_internal.c
@@ -100,6 +100,10 @@ OMX_ERRORTYPE OMXBase_PrivateInit(OMX_HANDLETYPE hComponent)
100 tStatus = OSAL_CreateEvent(&(pBaseCompPvt->pTriggerEvent)); 100 tStatus = OSAL_CreateEvent(&(pBaseCompPvt->pTriggerEvent));
101 OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); 101 OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources);
102 102
103 /*Create mutex for port disable*/
104 tStatus = OSAL_CreateMutex(&(pBaseCompPvt->pPortDisableMutex));
105 OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources);
106
103 OSAL_Memcpy(pBaseCompPvt->cTaskName, pBaseComp->cComponentName, strlen(pBaseComp->cComponentName)); 107 OSAL_Memcpy(pBaseCompPvt->cTaskName, pBaseComp->cComponentName, strlen(pBaseComp->cComponentName));
104 pBaseCompPvt->nStackSize = OMX_BASE_THREAD_STACKSIZE; 108 pBaseCompPvt->nStackSize = OMX_BASE_THREAD_STACKSIZE;
105 pBaseCompPvt->nPrioirty = OMX_BASE_THREAD_PRIORITY; 109 pBaseCompPvt->nPrioirty = OMX_BASE_THREAD_PRIORITY;
@@ -231,6 +235,13 @@ OMX_ERRORTYPE OMXBase_PrivateDeInit(OMX_HANDLETYPE hComponent)
231 } 235 }
232 pBaseCompPvt->pCmdPipeMutex = NULL; 236 pBaseCompPvt->pCmdPipeMutex = NULL;
233 } 237 }
238 if (pBaseCompPvt->pPortDisableMutex) {
239 tStatus = OSAL_DeleteMutex(pBaseCompPvt->pPortDisableMutex);
240 if( tStatus != OSAL_ErrNone ) {
241 eError = OMX_ErrorUndefined;
242 }
243 pBaseCompPvt->pPortDisableMutex = NULL;
244 }
234 245
235 OSAL_ReleaseMutex(pBaseCompPvt->pNewStateMutex); 246 OSAL_ReleaseMutex(pBaseCompPvt->pNewStateMutex);
236 247
@@ -1535,6 +1546,7 @@ void OMXBase_HandleFailEvent(OMX_HANDLETYPE hComponent, OMX_COMMANDTYPE eCmd,
1535 case OMX_CommandPortDisable : 1546 case OMX_CommandPortDisable :
1536 /*Close DIO on the relevant ports for both enable as well as disable 1547 /*Close DIO on the relevant ports for both enable as well as disable
1537 commands*/ 1548 commands*/
1549 OSAL_ObtainMutex(pBaseCompPvt->pPortDisableMutex, OSAL_SUSPEND);
1538 if( nPortIndex == OMX_ALL ) { 1550 if( nPortIndex == OMX_ALL ) {
1539 for( i = 0; i < pBaseComp->nNumPorts; i++ ) { 1551 for( i = 0; i < pBaseComp->nNumPorts; i++ ) {
1540 pPort = pBaseComp->pPorts[i]; 1552 pPort = pBaseComp->pPorts[i];
@@ -1555,6 +1567,7 @@ void OMXBase_HandleFailEvent(OMX_HANDLETYPE hComponent, OMX_COMMANDTYPE eCmd,
1555 } 1567 }
1556 } 1568 }
1557 } 1569 }
1570 OSAL_ReleaseMutex(pBaseCompPvt->pPortDisableMutex);
1558 break; 1571 break;
1559 1572
1560 default : 1573 default :