refactor: refactor `get_ffa_feature_test_target`
Change `get_ffa_feature_test_target` to return a `size_t` instead of an
`unsigned int`, because `size_t` is the return type of operators like
`sizeof()`.
Change `get_ffa_feature_test_target` to require its argument to be
non-null (and assert that it is). This function is only used for getting
the array of features to test, so there is no use case where passing a
non-null pointer would make sense.
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
Change-Id: I33597f1a2f7681eda59ece08062e48c28752c111
diff --git a/include/runtime_services/spm_common.h b/include/runtime_services/spm_common.h
index 4dd5e5c..b055c92 100644
--- a/include/runtime_services/spm_common.h
+++ b/include/runtime_services/spm_common.h
@@ -103,10 +103,10 @@
bool check_spmc_execution_level(void);
-unsigned int get_ffa_feature_test_target(
- const struct ffa_features_test **test_target);
+size_t get_ffa_feature_test_target(
+ const struct ffa_features_test **test_target);
bool ffa_features_test_targets(const struct ffa_features_test *targets,
- uint32_t test_target_size);
+ size_t test_target_size);
/**
* Helper to conduct a memory retrieve. This is to be called by the receiver
diff --git a/spm/common/sp_tests/sp_test_ffa.c b/spm/common/sp_tests/sp_test_ffa.c
index e7dd720..94576d1 100644
--- a/spm/common/sp_tests/sp_test_ffa.c
+++ b/spm/common/sp_tests/sp_test_ffa.c
@@ -83,9 +83,7 @@
{
const struct ffa_features_test *func_id_targets;
/* Get common features between tftf and cactus. */
- unsigned int test_target_size =
- get_ffa_feature_test_target(&func_id_targets);
- /* Specific to SPs. */
+ size_t test_target_size = get_ffa_feature_test_target(&func_id_targets);
struct ffa_features_test feature_id_targets[] = {
{"FFA_FEATURE_MEI", FFA_FEATURE_MEI, FFA_SUCCESS_SMC32, 0,
FFA_VERSION_1_1},
diff --git a/tftf/tests/runtime_services/secure_service/spm_common.c b/tftf/tests/runtime_services/secure_service/spm_common.c
index 753d491..80e5de7 100644
--- a/tftf/tests/runtime_services/secure_service/spm_common.c
+++ b/tftf/tests/runtime_services/secure_service/spm_common.c
@@ -210,15 +210,11 @@
*
* Returns number of elements in the *test_target.
*/
-unsigned int get_ffa_feature_test_target(
- const struct ffa_features_test **test_target)
+size_t get_ffa_feature_test_target(const struct ffa_features_test **test_target)
{
- if (test_target != NULL) {
- *test_target = ffa_feature_test_target;
- }
-
- return sizeof(ffa_feature_test_target) /
- sizeof(struct ffa_features_test);
+ assert(test_target != NULL);
+ *test_target = ffa_feature_test_target;
+ return ARRAY_SIZE(ffa_feature_test_target);
}
/**
@@ -226,7 +222,7 @@
* FFA_FEATURES calls.
*/
bool ffa_features_test_targets(const struct ffa_features_test *targets,
- uint32_t test_target_size)
+ size_t test_target_size)
{
bool ret = true;
diff --git a/tftf/tests/runtime_services/secure_service/test_ffa_setup_and_discovery.c b/tftf/tests/runtime_services/secure_service/test_ffa_setup_and_discovery.c
index 5effe53..1586fe6 100644
--- a/tftf/tests/runtime_services/secure_service/test_ffa_setup_and_discovery.c
+++ b/tftf/tests/runtime_services/secure_service/test_ffa_setup_and_discovery.c
@@ -98,8 +98,7 @@
FFA_VERSION_1_1},
{"FFA_YIELD_32", FFA_MSG_YIELD, FFA_ERROR},
};
- unsigned int test_target_size =
- get_ffa_feature_test_target(&func_ids_target);
+ size_t test_target_size = get_ffa_feature_test_target(&func_ids_target);
SKIP_TEST_IF_FFA_VERSION_LESS_THAN(1, 0);