SPM: Fix service allocation logic
Some partitions do not have services. An error will occur when
service pool is full and call the allocation API with argument
0 again.
Change-Id: Ia088f0577dfc1a4aa7964f190997c0c4c8c99fe0
Signed-off-by: Mingyang Sun <mingyang.sun@arm.com>
diff --git a/secure_fw/spm/cmsis_psa/spm_ipc.c b/secure_fw/spm/cmsis_psa/spm_ipc.c
index 9f4322e..1e547ef 100644
--- a/secure_fw/spm/cmsis_psa/spm_ipc.c
+++ b/secure_fw/spm/cmsis_psa/spm_ipc.c
@@ -668,7 +668,8 @@
struct service_t *p_service_allocated = NULL;
uint32_t num_of_services = sizeof(g_services) / sizeof(struct service_t);
- if ((service_count > num_of_services) ||
+ if ((service_count == 0) ||
+ (service_count > num_of_services) ||
(service_pool_pos >= num_of_services) ||
(service_pool_pos + service_count > num_of_services)) {
return NULL;
@@ -736,9 +737,13 @@
if (!partition) {
tfm_core_panic();
}
- service = tfm_allocate_service(p_cmninf->nservices);
- if (!service) {
- tfm_core_panic();
+ if (p_cmninf->nservices) {
+ service = tfm_allocate_service(p_cmninf->nservices);
+ if (!service) {
+ tfm_core_panic();
+ }
+ } else {
+ service = NULL;
}
partition->p_static = p_cmninf;