From c9512bca3b69dcb50ac839ce1f6d24a68be46986 Mon Sep 17 00:00:00 2001 From: Antonio Nino Diaz Date: Fri, 24 Aug 2018 16:30:29 +0100 Subject: Fix MISRA defects in BL31 common code Change-Id: I5993b425445ee794e6d2a792c244c0af53640655 Signed-off-by: Antonio Nino Diaz --- bl31/bl31_main.c | 11 ++++++++--- bl31/interrupt_mgmt.c | 42 +++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 24 deletions(-) (limited to 'bl31') diff --git a/bl31/bl31_main.c b/bl31/bl31_main.c index 066474124..650181ddc 100644 --- a/bl31/bl31_main.c +++ b/bl31/bl31_main.c @@ -103,9 +103,14 @@ void bl31_main(void) /* * If SPD had registerd an init hook, invoke it. */ - if (bl32_init) { + if (bl32_init != NULL) { INFO("BL31: Initializing BL32\n"); - (*bl32_init)(); + + int32_t rc = (*bl32_init)(); + + if (rc != 0) { + ERROR("BL31: BL32 initialization failed (rc = %d)", rc); + } } /* * We are ready to enter the next EL. Prepare entry into the image @@ -167,7 +172,7 @@ void bl31_prepare_next_image_entry(void) /* Program EL3 registers to enable entry into the next EL */ next_image_info = bl31_plat_get_next_image_ep_info(image_type); - assert(next_image_info); + assert(next_image_info != NULL); assert(image_type == GET_SECURITY_STATE(next_image_info->h.attr)); INFO("BL31: Preparing for EL3 exit to %s world\n", diff --git a/bl31/interrupt_mgmt.c b/bl31/interrupt_mgmt.c index b885a66ad..0df50b6d2 100644 --- a/bl31/interrupt_mgmt.c +++ b/bl31/interrupt_mgmt.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2014-2018, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -10,7 +10,6 @@ #include #include #include -#include /******************************************************************************* * Local structure and corresponding array to keep track of the state of the @@ -47,8 +46,8 @@ static intr_type_desc_t intr_type_descs[MAX_INTR_TYPES]; ******************************************************************************/ static int32_t validate_interrupt_type(uint32_t type) { - if (type == INTR_TYPE_S_EL1 || type == INTR_TYPE_NS || - type == INTR_TYPE_EL3) + if ((type == INTR_TYPE_S_EL1) || (type == INTR_TYPE_NS) || + (type == INTR_TYPE_EL3)) return 0; return -EINVAL; @@ -59,17 +58,16 @@ static int32_t validate_interrupt_type(uint32_t type) ******************************************************************************/ static int32_t validate_routing_model(uint32_t type, uint32_t flags) { - flags >>= INTR_RM_FLAGS_SHIFT; - flags &= INTR_RM_FLAGS_MASK; + uint32_t rm_flags = (flags >> INTR_RM_FLAGS_SHIFT) & INTR_RM_FLAGS_MASK; if (type == INTR_TYPE_S_EL1) - return validate_sel1_interrupt_rm(flags); + return validate_sel1_interrupt_rm(rm_flags); if (type == INTR_TYPE_NS) - return validate_ns_interrupt_rm(flags); + return validate_ns_interrupt_rm(rm_flags); if (type == INTR_TYPE_EL3) - return validate_el3_interrupt_rm(flags); + return validate_el3_interrupt_rm(rm_flags); return -EINVAL; } @@ -106,10 +104,12 @@ static void set_scr_el3_from_rm(uint32_t type, bit_pos = plat_interrupt_type_to_line(type, security_state); intr_type_descs[type].scr_el3[security_state] = flag << bit_pos; - /* Update scr_el3 only if there is a context available. If not, it + /* + * Update scr_el3 only if there is a context available. If not, it * will be updated later during context initialization which will obtain - * the scr_el3 value to be used via get_scr_el3_from_routing_model() */ - if (cm_get_context(security_state)) + * the scr_el3 value to be used via get_scr_el3_from_routing_model() + */ + if (cm_get_context(security_state) != NULL) cm_write_scr_el3_bit(security_state, bit_pos, flag); } @@ -124,11 +124,11 @@ int32_t set_routing_model(uint32_t type, uint32_t flags) int32_t rc; rc = validate_interrupt_type(type); - if (rc) + if (rc != 0) return rc; rc = validate_routing_model(type, flags); - if (rc) + if (rc != 0) return rc; /* Update the routing model in internal data structures */ @@ -149,7 +149,7 @@ int disable_intr_rm_local(uint32_t type, uint32_t security_state) { uint32_t bit_pos, flag; - assert(intr_type_descs[type].handler); + assert(intr_type_descs[type].handler != NULL); flag = get_interrupt_rm_flag(INTR_DEFAULT_RM, security_state); @@ -167,7 +167,7 @@ int enable_intr_rm_local(uint32_t type, uint32_t security_state) { uint32_t bit_pos, flag; - assert(intr_type_descs[type].handler); + assert(intr_type_descs[type].handler != NULL); flag = get_interrupt_rm_flag(intr_type_descs[type].flags, security_state); @@ -190,19 +190,19 @@ int32_t register_interrupt_type_handler(uint32_t type, int32_t rc; /* Validate the 'handler' parameter */ - if (!handler) + if (handler == NULL) return -EINVAL; /* Validate the 'flags' parameter */ - if (flags & INTR_TYPE_FLAGS_MASK) + if ((flags & INTR_TYPE_FLAGS_MASK) != 0U) return -EINVAL; /* Check if a handler has already been registered */ - if (intr_type_descs[type].handler) + if (intr_type_descs[type].handler != NULL) return -EALREADY; rc = set_routing_model(type, flags); - if (rc) + if (rc != 0) return rc; /* Save the handler */ @@ -218,7 +218,7 @@ int32_t register_interrupt_type_handler(uint32_t type, ******************************************************************************/ interrupt_type_handler_t get_interrupt_type_handler(uint32_t type) { - if (validate_interrupt_type(type)) + if (validate_interrupt_type(type) != 0) return NULL; return intr_type_descs[type].handler; -- cgit v1.2.3