Crypto: Optimize the IOVEC buffer memset operation

The memset always clears the full IOVEC buffers whereas we
need to clear only the used buffer.
Change the return type of tfm_crypto_clear_scratch() to 'void'
since it doesn't need to return value.

Change-Id: I30246bcabbe9957c35e6ae59d9e0ff5def9be01c
Signed-off-by: Summer Qin <summer.qin@arm.com>
diff --git a/secure_fw/partitions/crypto/crypto_init.c b/secure_fw/partitions/crypto/crypto_init.c
index 2f90638..648b76a 100644
--- a/secure_fw/partitions/crypto/crypto_init.c
+++ b/secure_fw/partitions/crypto/crypto_init.c
@@ -100,13 +100,11 @@
     return PSA_SUCCESS;
 }
 
-static psa_status_t tfm_crypto_clear_scratch(void)
+void tfm_crypto_clear_scratch(void)
 {
-    scratch.alloc_index = 0;
     scratch.owner = 0;
-    (void)tfm_memset(scratch.buf, 0, sizeof(scratch.buf));
-
-    return PSA_SUCCESS;
+    (void)tfm_memset(scratch.buf, 0, scratch.alloc_index);
+    scratch.alloc_index = 0;
 }
 
 static psa_status_t tfm_crypto_call_sfn(psa_msg_t *msg,
@@ -137,7 +135,7 @@
         /* Allocate necessary space in the internal scratch */
         status = tfm_crypto_alloc_scratch(msg->in_size[i], &alloc_buf_ptr);
         if (status != PSA_SUCCESS) {
-            (void)tfm_crypto_clear_scratch();
+            tfm_crypto_clear_scratch();
             return status;
         }
         /* Read from the IPC framework inputs into the scratch */
@@ -156,7 +154,7 @@
         /* Allocate necessary space for the output in the internal scratch */
         status = tfm_crypto_alloc_scratch(msg->out_size[i], &alloc_buf_ptr);
         if (status != PSA_SUCCESS) {
-            (void)tfm_crypto_clear_scratch();
+            tfm_crypto_clear_scratch();
             return status;
         }
         /* Populate the fields of the output to the secure function */
@@ -176,9 +174,7 @@
     }
 
     /* Clear the allocated internal scratch before returning */
-    if (tfm_crypto_clear_scratch() != PSA_SUCCESS) {
-        return PSA_ERROR_GENERIC_ERROR;
-    }
+    tfm_crypto_clear_scratch();
 
     return status;
 }