summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAntonio Nino Diaz <antonio.ninodiaz@arm.com>2018-10-04 09:55:23 +0100
committerAntonio Nino Diaz <antonio.ninodiaz@arm.com>2018-10-04 15:43:52 +0100
commit81542c00d0d3d0609cfedf91f8d6f455672af684 (patch)
tree6981c5d3041c2242239f6af9c407131894a8d12b /common
parent756fac649b31cf2c06c753adf3bebfc9d8644b60 (diff)
Remove some MISRA defects in common code
No functional changes. Change-Id: I9638e02acb9b22eb794ebf45aad84348a710287e Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
Diffstat (limited to 'common')
-rw-r--r--common/bl_common.c33
-rw-r--r--common/desc_image_load.c42
-rw-r--r--common/runtime_svc.c34
3 files changed, 56 insertions, 53 deletions
diff --git a/common/bl_common.c b/common/bl_common.c
index 60baa5bd..d12a17cf 100644
--- a/common/bl_common.c
+++ b/common/bl_common.c
@@ -48,8 +48,8 @@ static int dyn_is_auth_disabled(void)
uintptr_t page_align(uintptr_t value, unsigned dir)
{
/* Round up the limit to the next page boundary */
- if (value & (PAGE_SIZE - 1)) {
- value &= ~(PAGE_SIZE - 1);
+ if ((value & (PAGE_SIZE - 1U)) != 0U) {
+ value &= ~(PAGE_SIZE - 1U);
if (dir == UP)
value += PAGE_SIZE;
}
@@ -106,7 +106,7 @@ size_t get_image_size(unsigned int image_id)
uintptr_t dev_handle;
uintptr_t image_handle;
uintptr_t image_spec;
- size_t image_size = 0;
+ size_t image_size = 0U;
int io_result;
/* Obtain a reference to the image by querying the platform layer */
@@ -127,7 +127,7 @@ size_t get_image_size(unsigned int image_id)
/* Find the size of the image */
io_result = io_size(image_handle, &image_size);
- if ((io_result != 0) || (image_size == 0)) {
+ if ((io_result != 0) || (image_size == 0U)) {
WARN("Failed to determine the size of the image id=%u (%i)\n",
image_id, io_result);
}
@@ -182,12 +182,11 @@ static int load_image(unsigned int image_id, image_info_t *image_data)
return io_result;
}
- INFO("Loading image id=%u at address %p\n", image_id,
- (void *) image_base);
+ INFO("Loading image id=%u at address 0x%lx\n", image_id, image_base);
/* Find the size of the image */
io_result = io_size(image_handle, &image_size);
- if ((io_result != 0) || (image_size == 0)) {
+ if ((io_result != 0) || (image_size == 0U)) {
WARN("Failed to determine the size of the image id=%u (%i)\n",
image_id, io_result);
goto exit;
@@ -200,7 +199,11 @@ static int load_image(unsigned int image_id, image_info_t *image_data)
goto exit;
}
- image_data->image_size = image_size;
+ /*
+ * image_data->image_max_size is a uint32_t so image_size will always
+ * fit in image_data->image_size.
+ */
+ image_data->image_size = (uint32_t)image_size;
/* We have enough space so load the image now */
/* TODO: Consider whether to try to recover/retry a partially successful read */
@@ -210,15 +213,15 @@ static int load_image(unsigned int image_id, image_info_t *image_data)
goto exit;
}
- INFO("Image id=%u loaded: %p - %p\n", image_id, (void *) image_base,
- (void *) (image_base + image_size));
+ INFO("Image id=%u loaded: 0x%lx - 0x%lx\n", image_id, image_base,
+ (uintptr_t)(image_base + image_size));
exit:
- io_close(image_handle);
+ (void)io_close(image_handle);
/* Ignore improbable/unrecoverable error in 'close' */
/* TODO: Consider maintaining open device connection from this bootloader stage */
- io_dev_close(dev_handle);
+ (void)io_dev_close(dev_handle);
/* Ignore improbable/unrecoverable error in 'dev_close' */
return io_result;
@@ -274,7 +277,7 @@ static int load_auth_image_internal(unsigned int image_id,
* the file has been successfully loaded and authenticated and flush
* only for child images, not for the parents (certificates).
*/
- if (!is_parent_image) {
+ if (is_parent_image == 0) {
flush_dcache_range(image_data->image_base,
image_data->image_size);
}
@@ -296,7 +299,7 @@ int load_auth_image(unsigned int image_id, image_info_t *image_data)
do {
err = load_auth_image_internal(image_id, image_data, 0);
- } while (err != 0 && plat_try_next_boot_source());
+ } while ((err != 0) && (plat_try_next_boot_source() != 0));
return err;
}
@@ -306,7 +309,7 @@ int load_auth_image(unsigned int image_id, image_info_t *image_data)
******************************************************************************/
void print_entry_point_info(const entry_point_info_t *ep_info)
{
- INFO("Entry point address = %p\n", (void *)ep_info->pc);
+ INFO("Entry point address = 0x%lx\n", ep_info->pc);
INFO("SPSR = 0x%x\n", ep_info->spsr);
#define PRINT_IMAGE_ARG(n) \
diff --git a/common/desc_image_load.c b/common/desc_image_load.c
index 28745d41..b07fba33 100644
--- a/common/desc_image_load.c
+++ b/common/desc_image_load.c
@@ -35,12 +35,12 @@ void flush_bl_params_desc(void)
******************************************************************************/
int get_bl_params_node_index(unsigned int image_id)
{
- int index;
+ unsigned int index;
assert(image_id != INVALID_IMAGE_ID);
- for (index = 0; index < bl_mem_params_desc_num; index++) {
+ for (index = 0U; index < bl_mem_params_desc_num; index++) {
if (bl_mem_params_desc_ptr[index].image_id == image_id)
- return index;
+ return (int)index;
}
return -1;
@@ -72,17 +72,17 @@ bl_mem_params_node_t *get_bl_mem_params_node(unsigned int image_id)
******************************************************************************/
bl_load_info_t *get_bl_load_info_from_mem_params_desc(void)
{
- int index = 0;
+ unsigned int index = 0;
/* If there is no image to start with, return NULL */
- if (!bl_mem_params_desc_num)
+ if (bl_mem_params_desc_num == 0U)
return NULL;
/* Assign initial data structures */
bl_load_info_node_t *bl_node_info =
&bl_mem_params_desc_ptr[index].load_node_mem;
bl_load_info.head = bl_node_info;
- SET_PARAM_HEAD(&bl_load_info, PARAM_BL_LOAD_INFO, VERSION_2, 0);
+ SET_PARAM_HEAD(&bl_load_info, PARAM_BL_LOAD_INFO, VERSION_2, 0U);
/* Go through the image descriptor array and create the list */
for (; index < bl_mem_params_desc_num; index++) {
@@ -92,10 +92,10 @@ bl_load_info_t *get_bl_load_info_from_mem_params_desc(void)
bl_node_info->image_info = &bl_mem_params_desc_ptr[index].image_info;
/* Link next image if present */
- if ((index + 1) < bl_mem_params_desc_num) {
+ if ((index + 1U) < bl_mem_params_desc_num) {
/* Get the memory and link the next node */
bl_node_info->next_load_info =
- &bl_mem_params_desc_ptr[index + 1].load_node_mem;
+ &bl_mem_params_desc_ptr[index + 1U].load_node_mem;
bl_node_info = bl_node_info->next_load_info;
}
}
@@ -112,19 +112,19 @@ bl_load_info_t *get_bl_load_info_from_mem_params_desc(void)
******************************************************************************/
bl_params_t *get_next_bl_params_from_mem_params_desc(void)
{
- int count;
- unsigned int img_id = 0;
- int link_index = 0;
+ unsigned int count;
+ unsigned int img_id = 0U;
+ unsigned int link_index = 0U;
bl_params_node_t *bl_current_exec_node = NULL;
bl_params_node_t *bl_last_exec_node = NULL;
bl_mem_params_node_t *desc_ptr;
/* If there is no image to start with, return NULL */
- if (!bl_mem_params_desc_num)
+ if (bl_mem_params_desc_num == 0U)
return NULL;
/* Get the list HEAD */
- for (count = 0; count < bl_mem_params_desc_num; count++) {
+ for (count = 0U; count < bl_mem_params_desc_num; count++) {
desc_ptr = &bl_mem_params_desc_ptr[count];
@@ -140,13 +140,13 @@ bl_params_t *get_next_bl_params_from_mem_params_desc(void)
assert(next_bl_params.head != NULL);
/* Populate the HEAD information */
- SET_PARAM_HEAD(&next_bl_params, PARAM_BL_PARAMS, VERSION_2, 0);
+ SET_PARAM_HEAD(&next_bl_params, PARAM_BL_PARAMS, VERSION_2, 0U);
/*
* Go through the image descriptor array and create the list.
* This bounded loop is to make sure that we are not looping forever.
*/
- for (count = 0 ; count < bl_mem_params_desc_num; count++) {
+ for (count = 0U; count < bl_mem_params_desc_num; count++) {
desc_ptr = &bl_mem_params_desc_ptr[link_index];
@@ -161,7 +161,7 @@ bl_params_t *get_next_bl_params_from_mem_params_desc(void)
bl_current_exec_node->image_info = &desc_ptr->image_info;
bl_current_exec_node->ep_info = &desc_ptr->ep_info;
- if (bl_last_exec_node) {
+ if (bl_last_exec_node != NULL) {
/* Assert if loop detected */
assert(bl_last_exec_node->next_params_info == NULL);
@@ -179,7 +179,7 @@ bl_params_t *get_next_bl_params_from_mem_params_desc(void)
/* Get the index for the next hand-off image */
link_index = get_bl_params_node_index(img_id);
- assert((link_index > 0) &&
+ assert((link_index > 0U) &&
(link_index < bl_mem_params_desc_num));
}
@@ -243,17 +243,17 @@ void populate_next_bl_params_config(bl_params_t *bl2_to_next_bl_params)
* overwriting the previous initialisations.
*/
if (params_node == bl2_to_next_bl_params->head) {
- if (params_node->ep_info->args.arg1 == 0)
+ if (params_node->ep_info->args.arg1 == 0U)
params_node->ep_info->args.arg1 =
fw_config_base;
- if (params_node->ep_info->args.arg2 == 0)
+ if (params_node->ep_info->args.arg2 == 0U)
params_node->ep_info->args.arg2 =
hw_config_base;
} else {
- if (params_node->ep_info->args.arg0 == 0)
+ if (params_node->ep_info->args.arg0 == 0U)
params_node->ep_info->args.arg0 =
fw_config_base;
- if (params_node->ep_info->args.arg1 == 0)
+ if (params_node->ep_info->args.arg1 == 0U)
params_node->ep_info->args.arg1 =
hw_config_base;
}
diff --git a/common/runtime_svc.c b/common/runtime_svc.c
index 03f7f7ef..c30c0ecb 100644
--- a/common/runtime_svc.c
+++ b/common/runtime_svc.c
@@ -35,16 +35,16 @@ uintptr_t handle_runtime_svc(uint32_t smc_fid,
unsigned int flags)
{
u_register_t x1, x2, x3, x4;
- int index;
+ unsigned int index;
unsigned int idx;
const rt_svc_desc_t *rt_svc_descs;
- assert(handle);
+ assert(handle != NULL);
idx = get_unique_oen_from_smc_fid(smc_fid);
assert(idx < MAX_RT_SVCS);
index = rt_svc_descs_indices[idx];
- if (index < 0 || index >= (int)RT_SVC_DECS_NUM)
+ if (index >= RT_SVC_DECS_NUM)
SMC_RET1(handle, SMC_UNK);
rt_svc_descs = (rt_svc_desc_t *) RT_SVC_DESCS_START;
@@ -96,7 +96,7 @@ static int32_t validate_rt_svc_desc(const rt_svc_desc_t *desc)
void __init runtime_svc_init(void)
{
int rc = 0;
- unsigned int index, start_idx, end_idx;
+ uint8_t index, start_idx, end_idx;
rt_svc_desc_t *rt_svc_descs;
/* Assert the number of descriptors detected are less than maximum indices */
@@ -108,10 +108,10 @@ void __init runtime_svc_init(void)
return;
/* Initialise internal variables to invalid state */
- memset(rt_svc_descs_indices, -1, sizeof(rt_svc_descs_indices));
+ (void)memset(rt_svc_descs_indices, -1, sizeof(rt_svc_descs_indices));
rt_svc_descs = (rt_svc_desc_t *) RT_SVC_DESCS_START;
- for (index = 0; index < RT_SVC_DECS_NUM; index++) {
+ for (index = 0U; index < RT_SVC_DECS_NUM; index++) {
rt_svc_desc_t *service = &rt_svc_descs[index];
/*
@@ -120,7 +120,7 @@ void __init runtime_svc_init(void)
* of this service.
*/
rc = validate_rt_svc_desc(service);
- if (rc) {
+ if (rc != 0) {
ERROR("Invalid runtime service descriptor %p\n",
(void *) service);
panic();
@@ -133,9 +133,9 @@ void __init runtime_svc_init(void)
* an initialisation routine defined. Call the initialisation
* routine for this runtime service, if it is defined.
*/
- if (service->init) {
+ if (service->init != NULL) {
rc = service->init();
- if (rc) {
+ if (rc != 0) {
ERROR("Error initializing runtime service %s\n",
service->name);
continue;
@@ -149,15 +149,15 @@ void __init runtime_svc_init(void)
* entity range.
*/
#if SMCCC_MAJOR_VERSION == 1
- start_idx = get_unique_oen(service->start_oen,
- service->call_type);
- end_idx = get_unique_oen(service->end_oen,
- service->call_type);
+ start_idx = (uint8_t)get_unique_oen(service->start_oen,
+ service->call_type);
+ end_idx = (uint8_t)get_unique_oen(service->end_oen,
+ service->call_type);
#elif SMCCC_MAJOR_VERSION == 2
- start_idx = get_rt_desc_idx(service->start_oen,
- service->is_vendor);
- end_idx = get_rt_desc_idx(service->end_oen,
- service->is_vendor);
+ start_idx = (uint8_t)get_rt_desc_idx(service->start_oen,
+ service->is_vendor);
+ end_idx = (uint8_t)get_rt_desc_idx(service->end_oen,
+ service->is_vendor);
#endif
assert(start_idx <= end_idx);
assert(end_idx < MAX_RT_SVCS);