teec: Fix temp memory allocation 02/155002/2
authorLukasz Kostyra <l.kostyra@samsung.com>
Wed, 11 Oct 2017 16:26:48 +0000 (18:26 +0200)
committerLukasz Kostyra <l.kostyra@samsung.com>
Wed, 11 Oct 2017 16:45:08 +0000 (18:45 +0200)
When allocating shared memory for temp memory reference in operation,
TEECLib didn't set proper memory flag. This caused an error during
operation pre-processing.

Change-Id: I8b1fa13ac5d8feca1f596f514ab40e3f03d2198c

TEECLib/src/teec_api.c

index 172912b..a84aac7 100644 (file)
@@ -318,6 +318,14 @@ static TEEC_Result preProcessOperation(TEEC_Session *session,
                                            sizeof(TEEC_SharedMemory));
                                        tmpSharedMem[i]->size = operation->params[i].tmpref.size;
                                        tmpSharedMem[i]->buffer = operation->params[i].tmpref.buffer;
+                                       if (type == TEEC_MEMREF_TEMP_INPUT) {
+                                               tmpSharedMem[i]->flags = TEEC_MEM_INPUT;
+                                       } else if (type == TEEC_MEMREF_TEMP_OUTPUT) {
+                                               tmpSharedMem[i]->flags = TEEC_MEM_OUTPUT;
+                                       } else if (type == TEEC_MEMREF_TEMP_INOUT) {
+                                               tmpSharedMem[i]->flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
+                                       }
+
                                        result = TEEC_RegisterSharedMemory(
                                            ((TEEC_SessionImp*)session->imp)->context, tmpSharedMem[i]);
                                        if (result != TEEC_SUCCESS) {
@@ -329,14 +337,8 @@ static TEEC_Result preProcessOperation(TEEC_Session *session,
                                                }
                                                return result;
                                        }
-                                       if (type == TEEC_MEMREF_TEMP_INPUT) {
-                                               tmpSharedMem[i]->flags = TEEC_MEM_INPUT;
-                                               memcpy(((TEEC_SharedMemoryImp*)tmpSharedMem[i]->imp)->allocPtr,
-                                                   tmpSharedMem[i]->buffer, tmpSharedMem[i]->size);
-                                       } else if (type == TEEC_MEMREF_TEMP_OUTPUT)
-                                               tmpSharedMem[i]->flags = TEEC_MEM_OUTPUT;
-                                       else {
-                                               tmpSharedMem[i]->flags = TEEC_MEM_INPUT | TEEC_MEM_OUTPUT;
+
+                                       if (type & TEEC_MEMREF_TEMP_INPUT) {
                                                memcpy(((TEEC_SharedMemoryImp*)tmpSharedMem[i]->imp)->allocPtr,
                                                    tmpSharedMem[i]->buffer, tmpSharedMem[i]->size);
                                        }