aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--secure_fw/partitions/psa_proxy/psa_proxy.c2
-rw-r--r--secure_fw/spm/cmsis_psa/spm_ipc.c2
-rw-r--r--secure_fw/spm/cmsis_psa/tfm_pools.c7
-rw-r--r--secure_fw/spm/cmsis_psa/tfm_pools.h36
4 files changed, 11 insertions, 36 deletions
diff --git a/secure_fw/partitions/psa_proxy/psa_proxy.c b/secure_fw/partitions/psa_proxy/psa_proxy.c
index 7864ef6849..49347b6f17 100644
--- a/secure_fw/partitions/psa_proxy/psa_proxy.c
+++ b/secure_fw/partitions/psa_proxy/psa_proxy.c
@@ -40,7 +40,7 @@ static inline psa_handle_t * allocate_forward_handle(void)
static inline void deallocate_forward_handle(psa_handle_t *h)
{
- tfm_pool_free(h);
+ tfm_pool_free(forward_handle_pool, h);
}
static psa_status_t forward_psa_call_to_secure_enclave(const psa_msg_t *msg)
diff --git a/secure_fw/spm/cmsis_psa/spm_ipc.c b/secure_fw/spm/cmsis_psa/spm_ipc.c
index d2067c1ddc..b1ec03f25a 100644
--- a/secure_fw/spm/cmsis_psa/spm_ipc.c
+++ b/secure_fw/spm/cmsis_psa/spm_ipc.c
@@ -189,7 +189,7 @@ int32_t tfm_spm_free_conn_handle(struct tfm_spm_service_t *service,
BI_LIST_REMOVE_NODE(&conn_handle->list);
/* Back handle buffer to pool */
- tfm_pool_free(conn_handle);
+ tfm_pool_free(conn_handle_pool, conn_handle);
return SPM_SUCCESS;
}
diff --git a/secure_fw/spm/cmsis_psa/tfm_pools.c b/secure_fw/spm/cmsis_psa/tfm_pools.c
index 835674f720..f298340054 100644
--- a/secure_fw/spm/cmsis_psa/tfm_pools.c
+++ b/secure_fw/spm/cmsis_psa/tfm_pools.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -43,7 +43,6 @@ int32_t tfm_pool_init(struct tfm_pool_instance_t *pool, size_t poolsz,
pchunk = (struct tfm_pool_chunk_t *)pool->chunks;
for (i = 0; i < num; i++) {
- pchunk->pool = pool;
BI_LIST_INSERT_BEFORE(&pool->chunks_list, &pchunk->list);
pchunk = (struct tfm_pool_chunk_t *)&pchunk->data[chunksz];
}
@@ -77,13 +76,11 @@ void *tfm_pool_alloc(struct tfm_pool_instance_t *pool)
return &pchunk->data;
}
-void tfm_pool_free(void *ptr)
+void tfm_pool_free(struct tfm_pool_instance_t *pool, void *ptr)
{
struct tfm_pool_chunk_t *pchunk;
- struct tfm_pool_instance_t *pool;
pchunk = TFM_GET_CONTAINER_PTR(ptr, struct tfm_pool_chunk_t, data);
- pool = (struct tfm_pool_instance_t *)pchunk->pool;
BI_LIST_INSERT_BEFORE(&pool->chunks_list, &pchunk->list);
}
diff --git a/secure_fw/spm/cmsis_psa/tfm_pools.h b/secure_fw/spm/cmsis_psa/tfm_pools.h
index e9c19dc1d7..6f2f30da8f 100644
--- a/secure_fw/spm/cmsis_psa/tfm_pools.h
+++ b/secure_fw/spm/cmsis_psa/tfm_pools.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
@@ -8,42 +8,22 @@
#define __TFM_POOLS_H__
#include <stdbool.h>
-
#include "lists.h"
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * Resource pool - few known size resources allocation/free is required,
- * so pool is more applicable than heap.
- */
-
/*
* Pool Instance:
* [ Pool Instance ] + N * [ Pool Chunks ]
*/
struct tfm_pool_chunk_t {
struct bi_list_node_t list; /* Chunk list */
- void *pool; /* Point to the parent pool */
- uint8_t data[0]; /* Data indicator */
-};
-
-/*
- * tfm_pool_chunk_t minus the zero length "data" member,
- * required for standards compliant C
- */
-struct tfm_pool_chunk_s_t {
- struct bi_list_node_t list; /* Chunk list */
- void *pool; /* Point to the parent pool */
+ uint8_t data[]; /* Data indicator */
};
struct tfm_pool_instance_t {
size_t chunksz; /* Chunks size of pool member */
size_t chunk_count; /* A number of chunks in the pool */
struct bi_list_node_t chunks_list; /* Chunk list head in pool */
- struct tfm_pool_chunk_s_t chunks[0]; /* Data indicator */
+ uint8_t chunks[]; /* Data indicator */
};
/*
@@ -57,7 +37,7 @@ struct tfm_pool_instance_t {
static uint8_t name##_pool_buf[((chunksz) + \
sizeof(struct tfm_pool_chunk_t)) * (num) \
+ sizeof(struct tfm_pool_instance_t)] \
- __attribute__((aligned(4))); \
+ __attribute__((aligned(4))); \
static struct tfm_pool_instance_t *name = \
(struct tfm_pool_instance_t *)name##_pool_buf
@@ -96,9 +76,11 @@ void *tfm_pool_alloc(struct tfm_pool_instance_t *pool);
/**
* \brief Free the allocated memory.
*
+ * \param[in] pool pool pointer decleared by \ref TFM_POOL_DECLARE
+ *
* \param[in] ptr Buffer pointer want to free.
*/
-void tfm_pool_free(void *ptr);
+void tfm_pool_free(struct tfm_pool_instance_t *pool, void *ptr);
/**
* \brief Checks whether a pointer points to a chunk data in the pool.
@@ -113,8 +95,4 @@ void tfm_pool_free(void *ptr);
bool is_valid_chunk_data_in_pool(struct tfm_pool_instance_t *pool,
uint8_t *data);
-#ifdef __cplusplus
-}
-#endif
-
#endif /* __TFM_POOLS_H__ */