From 45bf1569e185628168134446b3168f958089ae8d Mon Sep 17 00:00:00 2001 From: Krzysztof Dynowski Date: Thu, 7 Dec 2017 16:34:10 +0100 Subject: [PATCH] remove postProc when preProc failed, minor optimalizations Change-Id: I831e26f8c237b675f668d4a13002b5cd88dd7411 --- TEECLib/src/teec_api.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/TEECLib/src/teec_api.c b/TEECLib/src/teec_api.c index e269e02..e4cb0c2 100644 --- a/TEECLib/src/teec_api.c +++ b/TEECLib/src/teec_api.c @@ -270,13 +270,13 @@ static uint32_t checkContext(TEEC_Context *context) TEEC_Result tempSharedMemAllocate(TEEC_SharedMemory** tmpSharedMem, uint32_t type, TEEC_Context* context, TEEC_Parameter param) { + LOGD(TEEC_LIB, "Entry"); TEEC_Result result; *tmpSharedMem = (TEEC_SharedMemory *)OsaMalloc(sizeof(TEEC_SharedMemory)); if (!*tmpSharedMem) return TEEC_ERROR_OUT_OF_MEMORY; (*tmpSharedMem)->size = param.tmpref.size; (*tmpSharedMem)->buffer = param.tmpref.buffer; - (*tmpSharedMem)->flags = type & (TEEC_MEM_INPUT | TEEC_MEM_OUTPUT); result = TEEC_RegisterSharedMemory(context, *tmpSharedMem); @@ -321,9 +321,8 @@ static TEEC_Result preProcessOperation(TEEC_Session *session, TEEC_Operation *operation, OperationData *op, TEEC_SharedMemory *tmpSharedMem[4]) { - TEEC_Context *context = NULL; - LOGD(TEEC_LIB, "Entry"); + TEEC_Context *context = NULL; TEEC_RegisteredMemoryReference *memref; TEEC_SharedMemoryImp *memref_imp; TEEC_Result result = TEEC_SUCCESS; @@ -334,12 +333,13 @@ static TEEC_Result preProcessOperation(TEEC_Session *session, LOGE(TEEC_LIB, "Bad parameters"); return TEEC_ERROR_BAD_PARAMETERS; } - context = ((TEEC_SessionImp *)session->imp)->context; // Check if output Operation structure is valid if (!op) return TEEC_ERROR_GENERIC; + context = ((TEEC_SessionImp *)session->imp)->context; + // Initialize output Operation structure paramtypes to NONE op->paramTypes = (TEE_PARAM_TYPE_NONE << 24) | (TEE_PARAM_TYPE_NONE << 16) | (TEE_PARAM_TYPE_NONE << 8) | TEE_PARAM_TYPE_NONE; @@ -377,7 +377,6 @@ static TEEC_Result preProcessOperation(TEEC_Session *session, * specifications, so assign them without modifications. */ op->paramTypes |= type << (8 * i); - if (!tmpSharedMem[i]) { result = tempSharedMemAllocate(&tmpSharedMem[i], type, context, operation->params[i]); if (result != TEEC_SUCCESS) @@ -740,7 +739,7 @@ TEEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context, // Check if the context is initialized if (!checkContext(context)) { - LOGE(TEEC_LIB, "Invalid context"); + LOGE(TEEC_LIB, "Invalid context %p", context); return TEEC_ERROR_BAD_PARAMETERS; } @@ -770,7 +769,7 @@ TEEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context, * TEEC_CONFIG_SHAREDMEM_MAX_SIZE and less than PAGE_SIZE. */ if (sharedMem->size > TEEC_CONFIG_SHAREDMEM_MAX_SIZE) { - LOGE(TEEC_LIB, "Shared Memory size is too large 0x%x", sharedMem->size); + LOGE(TEEC_LIB, "Shared Memory size is too large %u > %u", sharedMem->size, TEEC_CONFIG_SHAREDMEM_MAX_SIZE); return TEEC_ERROR_BAD_PARAMETERS; } @@ -1089,9 +1088,10 @@ TEEC_Result TEEC_OpenSession(TEEC_Context *context, TEEC_Session *session, OpenSessionData os; OperationData op; TEEC_SharedMemory *tmpSharedMem[4]; - memset(tmpSharedMem, 0x0, sizeof(TEEC_SharedMemory *) * 4); uint32_t i; + memset(tmpSharedMem, 0x0, sizeof(tmpSharedMem)); + // Check if the context, session and UUID is valid if (!session || !context || !destination) { LOGE(TEEC_LIB, "Invalid input parameters"); @@ -1165,8 +1165,6 @@ TEEC_Result TEEC_OpenSession(TEEC_Context *context, TEEC_Session *session, OsaFree(session_imp); session->imp = NULL; - if (operation) postProcessOperation(operation, &op, tmpSharedMem); - /* temp memref cleanup & release */ for (i = 0; i < 4; i++) { if (tmpSharedMem[i]) { @@ -1343,9 +1341,10 @@ TEEC_Result TEEC_InvokeCommand(TEEC_Session *session, uint32_t commandID, InvokeCommandData ic; OperationData op; TEEC_SharedMemory *tmpSharedMem[4]; - memset(tmpSharedMem, 0x0, sizeof(TEEC_SharedMemory *) * 4); uint32_t i; + memset(tmpSharedMem, 0x0, sizeof(tmpSharedMem)); + // Check if Session is valid if (!session) { LOGE(TEEC_LIB, "NULL session"); @@ -1386,8 +1385,6 @@ TEEC_Result TEEC_InvokeCommand(TEEC_Session *session, uint32_t commandID, if (result != TEEC_SUCCESS) { LOGE(TEEC_LIB, "preProcessOperation failed"); - if (operation) postProcessOperation(operation, &op, tmpSharedMem); - /* temp memref cleanup & release */ for (i = 0; i < 4; i++) { if (tmpSharedMem[i]) { -- 2.7.4