Attest: Improve code quality
This patch fixes the following things:
* avoid implicit casting by using matching types or casting
* be explicit about return values of functions not checked
* fix indentation of code
* remove whitespaces
Change-Id: I8264b177d483d9f9f5f9e43e83f2268d0182d396
Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
diff --git a/interface/src/tfm_initial_attestation_api.c b/interface/src/tfm_initial_attestation_api.c
index 826c667..f9ab4ce 100644
--- a/interface/src/tfm_initial_attestation_api.c
+++ b/interface/src/tfm_initial_attestation_api.c
@@ -25,7 +25,7 @@
psa_handle_t handle = PSA_NULL_HANDLE;
psa_status_t status;
#else
- uint32_t res;
+ int32_t res;
#endif
psa_invec in_vec[] = {
{challenge_obj, challenge_size}
@@ -60,7 +60,7 @@
(uint32_t)in_vec, IOVEC_LEN(in_vec),
(uint32_t)out_vec, IOVEC_LEN(out_vec));
- if (res == PSA_ATTEST_ERR_SUCCESS) {
+ if (res == (int32_t)PSA_ATTEST_ERR_SUCCESS) {
*token_size = out_vec[0].len;
}
diff --git a/secure_fw/services/initial_attestation/attestation_core.c b/secure_fw/services/initial_attestation/attestation_core.c
index cff0fbe..33d86a1 100644
--- a/secure_fw/services/initial_attestation/attestation_core.c
+++ b/secure_fw/services/initial_attestation/attestation_core.c
@@ -113,12 +113,12 @@
break;
case 2:
/* Avoid unaligned access */
- tfm_memcpy(&uint16, int_ptr, sizeof(uint16));
+ (void)tfm_memcpy(&uint16, int_ptr, sizeof(uint16));
*value = (uint32_t)uint16;
break;
case 4:
/* Avoid unaligned access */
- tfm_memcpy(value, int_ptr, sizeof(uint32_t));
+ (void)tfm_memcpy(value, int_ptr, sizeof(uint32_t));
break;
default:
return -1;
@@ -164,7 +164,7 @@
tlv_curr = boot_data.data;
} else {
/* Any subsequent call set to the next TLV entry */
- tfm_memcpy(&tlv_entry, *tlv_ptr, SHARED_DATA_ENTRY_HEADER_SIZE);
+ (void)tfm_memcpy(&tlv_entry, *tlv_ptr, SHARED_DATA_ENTRY_HEADER_SIZE);
tlv_curr = (*tlv_ptr) + tlv_entry.tlv_len;
}
@@ -173,7 +173,7 @@
*/
for (; tlv_curr < tlv_end; tlv_curr += tlv_entry.tlv_len) {
/* Create local copy to avoid unaligned access */
- tfm_memcpy(&tlv_entry, tlv_curr, SHARED_DATA_ENTRY_HEADER_SIZE);
+ (void)tfm_memcpy(&tlv_entry, tlv_curr, SHARED_DATA_ENTRY_HEADER_SIZE);
if (GET_IAS_MODULE(tlv_entry.tlv_type) == module) {
*claim = GET_IAS_CLAIM(tlv_entry.tlv_type);
*tlv_ptr = tlv_curr;
@@ -319,7 +319,7 @@
QCBOREncodeContext *cbor_encode_ctx;
/* Create local copy to avoid unaligned access */
- tfm_memcpy(&tlv_entry, tlv_address, SHARED_DATA_ENTRY_HEADER_SIZE);
+ (void)tfm_memcpy(&tlv_entry, tlv_address, SHARED_DATA_ENTRY_HEADER_SIZE);
tlv_len = tlv_entry.tlv_len;
tlv_id = GET_IAS_CLAIM(tlv_entry.tlv_type);
@@ -333,10 +333,10 @@
/* Look up all measurement TLV entry which belongs to the SW component */
while (found) {
- /* Here only measurement claims are added to the token */
- if (GET_IAS_MEASUREMENT_CLAIM(tlv_id)) {
+ /* Here only measurement claims are added to the token */
+ if (GET_IAS_MEASUREMENT_CLAIM(tlv_id)) {
claim_value.ptr = tlv_ptr + SHARED_DATA_ENTRY_HEADER_SIZE;
- claim_value.len = tlv_len - SHARED_DATA_ENTRY_HEADER_SIZE;
+ claim_value.len = tlv_len - SHARED_DATA_ENTRY_HEADER_SIZE;
res = attest_add_sw_component_claim(token_ctx,
tlv_id,
&claim_value);
@@ -384,9 +384,10 @@
uint32_t measurement_claim_cnt = 0;
struct q_useful_buf_c claim_value;
QCBOREncodeContext *cbor_encode_ctx;
+ enum psa_attest_err_t res;
/* Create local copy to avoid unaligned access */
- tfm_memcpy(&tlv_entry, tlv_address, SHARED_DATA_ENTRY_HEADER_SIZE);
+ (void)tfm_memcpy(&tlv_entry, tlv_address, SHARED_DATA_ENTRY_HEADER_SIZE);
tlv_len = tlv_entry.tlv_len;
tlv_id = GET_IAS_CLAIM(tlv_entry.tlv_type);
@@ -394,23 +395,32 @@
cbor_encode_ctx = attest_token_borrow_cbor_cntxt(token_ctx);
QCBOREncode_OpenMap(cbor_encode_ctx);
- /*Look up all TLV entry which belongs to the same SW component */
+ /* Look up all TLV entry which belongs to the same SW component */
while (found) {
/* Check whether claim is measurement claim */
if (GET_IAS_MEASUREMENT_CLAIM(tlv_id)) {
if (measurement_claim_cnt == 0) {
/* Call only once when first measurement claim found */
measurement_claim_cnt++;
- attest_add_single_sw_measurment(token_ctx,
- module,
- tlv_ptr,
- EAT_SW_COMPONENT_NOT_NESTED);
+ res = attest_add_single_sw_measurment(
+ token_ctx,
+ module,
+ tlv_ptr,
+ EAT_SW_COMPONENT_NOT_NESTED);
+ if (res != PSA_ATTEST_ERR_SUCCESS) {
+ return res;
+ }
}
} else {
/* Adding top level claims */
claim_value.ptr = tlv_ptr + SHARED_DATA_ENTRY_HEADER_SIZE;
- claim_value.len = tlv_len - SHARED_DATA_ENTRY_HEADER_SIZE;
- attest_add_sw_component_claim(token_ctx, tlv_id, &claim_value);
+ claim_value.len = tlv_len - SHARED_DATA_ENTRY_HEADER_SIZE;
+ res = attest_add_sw_component_claim(token_ctx,
+ tlv_id,
+ &claim_value);
+ if (res != PSA_ATTEST_ERR_SUCCESS) {
+ return res;
+ }
}
/* Look up next entry which belongs to SW component */
@@ -445,6 +455,7 @@
uint32_t cnt = 0;
uint32_t module;
QCBOREncodeContext *cbor_encode_ctx;
+ enum psa_attest_err_t res;
/* Starting from module 1, because module 0 contains general claims which
* are not related to SW module(i.e: boot_seed, etc.)
@@ -470,7 +481,10 @@
QCBOREncode_OpenArrayInMapN(cbor_encode_ctx,
EAT_CBOR_ARM_LABEL_SW_COMPONENTS);
}
- attest_add_single_sw_component(token_ctx, module, tlv_ptr);
+ res = attest_add_single_sw_component(token_ctx, module, tlv_ptr);
+ if (res != PSA_ATTEST_ERR_SUCCESS) {
+ return res;
+ }
}
}
@@ -860,7 +874,7 @@
}
if (found_option_flags) {
- tfm_memcpy(option_flags, challenge->ptr, option_flags_size);
+ (void)tfm_memcpy(option_flags, challenge->ptr, option_flags_size);
/* Lower three bits are the key select */
*key_select = *option_flags & 0x7;
diff --git a/secure_fw/services/initial_attestation/tfm_attestation.c b/secure_fw/services/initial_attestation/tfm_attestation.c
index 94b6caa..f4b1acd 100644
--- a/secure_fw/services/initial_attestation/tfm_attestation.c
+++ b/secure_fw/services/initial_attestation/tfm_attestation.c
@@ -22,15 +22,15 @@
{
enum psa_attest_err_t attest_res = PSA_ATTEST_ERR_SUCCESS;
#ifndef TFM_PSA_API
- enum tfm_status_e tfm_res;
+ int32_t tfm_res;
- tfm_res = tfm_core_memory_permission_check(addr, size, access);
+ tfm_res = tfm_core_memory_permission_check(addr, size, (int32_t)access);
if (tfm_res) {
- attest_res = PSA_ATTEST_ERR_INVALID_INPUT;
- }
+ attest_res = PSA_ATTEST_ERR_INVALID_INPUT;
+ }
#endif
- return attest_res;
+ return attest_res;
}
enum psa_attest_err_t
@@ -38,12 +38,12 @@
{
enum psa_attest_err_t attest_res = PSA_ATTEST_ERR_SUCCESS;
#ifndef TFM_PSA_API
- enum tfm_status_e tfm_res;
+ int32_t tfm_res;
- tfm_res = tfm_core_get_caller_client_id(caller_id);
+ tfm_res = tfm_core_get_caller_client_id(caller_id);
if (tfm_res) {
- attest_res = PSA_ATTEST_ERR_CLAIM_UNAVAILABLE;
- }
+ attest_res = PSA_ATTEST_ERR_CLAIM_UNAVAILABLE;
+ }
#else
*caller_id = g_attest_caller_id;
#endif
@@ -66,10 +66,10 @@
boot_data->header.tlv_magic = SHARED_DATA_TLV_INFO_MAGIC;
boot_data->header.tlv_tot_len = SHARED_DATA_HEADER_SIZE;
#else
- enum tfm_status_e tfm_res;
+ int32_t tfm_res;
tfm_res = tfm_core_get_boot_data(major_type, boot_data, len);
- if (tfm_res != TFM_SUCCESS) {
+ if (tfm_res != (int32_t)TFM_SUCCESS) {
attest_res = PSA_ATTEST_ERR_INIT_FAILED;
}
#endif /* BL2 */
diff --git a/secure_fw/services/initial_attestation/tfm_attestation_secure_api.c b/secure_fw/services/initial_attestation/tfm_attestation_secure_api.c
index 8819a81..d403839 100644
--- a/secure_fw/services/initial_attestation/tfm_attestation_secure_api.c
+++ b/secure_fw/services/initial_attestation/tfm_attestation_secure_api.c
@@ -67,7 +67,8 @@
*token_size = out_vec[0].len;
}
#else
- if (tfm_core_set_buffer_area(TFM_BUFFER_SHARE_SCRATCH) != TFM_SUCCESS) {
+ if (tfm_core_set_buffer_area(TFM_BUFFER_SHARE_SCRATCH) !=
+ (int32_t)TFM_SUCCESS) {
return PSA_ATTEST_ERR_GENERAL;
}
@@ -85,7 +86,7 @@
token_buff = (uint8_t *)(challenge_buff + challenge_size);
/* Copy challenge object to scratch area */
- tfm_memcpy(challenge_buff, challenge_obj, challenge_size);
+ (void)tfm_memcpy(challenge_buff, challenge_obj, challenge_size);
in_vec[0].base = challenge_buff;
in_vec[0].len = challenge_size;
@@ -94,8 +95,8 @@
out_vec[0].len = *token_size;
status = tfm_initial_attest_get_token_veneer(in_vec, 1, out_vec, 1);
- if (status == PSA_ATTEST_ERR_SUCCESS) {
- tfm_memcpy(token, out_vec[0].base, out_vec[0].len);
+ if (status == (psa_status_t)PSA_ATTEST_ERR_SUCCESS) {
+ (void)tfm_memcpy(token, out_vec[0].base, out_vec[0].len);
*token_size = out_vec[0].len;
}
#endif
@@ -142,7 +143,8 @@
return PSA_ATTEST_ERR_GENERAL;
}
#else
- if (tfm_core_set_buffer_area(TFM_BUFFER_SHARE_SCRATCH) != TFM_SUCCESS) {
+ if (tfm_core_set_buffer_area(TFM_BUFFER_SHARE_SCRATCH) !=
+ (int32_t)TFM_SUCCESS) {
return PSA_ATTEST_ERR_GENERAL;
}
@@ -161,7 +163,7 @@
status = tfm_initial_attest_get_token_size_veneer(¶m->in_vec, 1,
¶m->out_vec, 1);
- if (status == PSA_ATTEST_ERR_SUCCESS) {
+ if (status == (psa_status_t)PSA_ATTEST_ERR_SUCCESS) {
*token_size = param->token_size;
}
#endif