SPM: Optimize the PSA API error handling process

In SPM implementation, message is a struct inside connection
handle struct and therefore it is unnecessary to check whether
the message pointer is NULL.

This patch:
- Skips checking message pointer after getting it from the
  connection handle.
- Returns an error code instead of calling tfm_core_panic()
  in some error processing.

Change-Id: Id45e63f8bbdd3d21db3ee32b43f4553ab7520a8f
Signed-off-by: Mingyang Sun <mingyang.sun@arm.com>
diff --git a/secure_fw/spm/ffm/psa_api.c b/secure_fw/spm/ffm/psa_api.c
index ec5580d..5d5d2d8 100644
--- a/secure_fw/spm/ffm/psa_api.c
+++ b/secure_fw/spm/ffm/psa_api.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2022, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -193,10 +193,6 @@
     }
 
     msg = tfm_spm_get_msg_buffer_from_conn_handle(connect_handle);
-    if (!msg) {
-        /* Have no enough resource to create message */
-        return PSA_ERROR_CONNECTION_BUSY;
-    }
 
     handle = tfm_spm_to_user_handle(connect_handle);
     /* No input or output needed for connect message */
@@ -250,7 +246,7 @@
 
         service = GET_STATELESS_SERVICE(index);
         if (!service) {
-            tfm_core_panic();
+            return PSA_ERROR_PROGRAMMER_ERROR;
         }
 
         sid = service->p_ldinf->sid;
@@ -306,11 +302,11 @@
         }
 
         service = conn_handle->internal_msg.service;
-    }
 
-    if (!service) {
-        /* FixMe: Need to implement one mechanism to resolve this failure. */
-        tfm_core_panic();
+        if (!service) {
+            /* FixMe: Need to implement a mechanism to resolve this failure. */
+            return PSA_ERROR_PROGRAMMER_ERROR;
+        }
     }
 
     privileged = tfm_spm_get_caller_privilege_mode();
@@ -385,10 +381,6 @@
      * Service or incorrectly formatted.
      */
     msg = tfm_spm_get_msg_buffer_from_conn_handle(conn_handle);
-    if (!msg) {
-        /* FixMe: Need to implement one mechanism to resolve this failure. */
-        return PSA_ERROR_PROGRAMMER_ERROR;
-    }
 
     tfm_spm_fill_msg(msg, service, handle, type, client_id,
                      invecs, in_num, outvecs, out_num, outptr);
@@ -428,14 +420,10 @@
     service = conn_handle->internal_msg.service;
     if (!service) {
         /* FixMe: Need to implement one mechanism to resolve this failure. */
-        tfm_core_panic();
+        return PSA_ERROR_PROGRAMMER_ERROR;
     }
 
     msg = tfm_spm_get_msg_buffer_from_conn_handle(conn_handle);
-    if (!msg) {
-        /* FixMe: Need to implement one mechanism to resolve this failure. */
-        tfm_core_panic();
-    }
 
     /*
      * It is a PROGRAMMER ERROR if the connection is currently handling a