From 466bb285c6985027c75a230e39f2ae246fd07971 Mon Sep 17 00:00:00 2001 From: Zelalem Date: Wed, 5 Feb 2020 14:12:39 -0600 Subject: coverity: Fix MISRA null pointer violations Fix code that violates the MISRA rule: MISRA C-2012 Rule 11.9: Literal "0" shall not be used as null pointer constant. The fix explicitly checks whether a pointer is NULL. Change-Id: Ibc318dc0f464982be9a34783f24ccd1d44800551 Signed-off-by: Zelalem --- bl1/bl1_main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'bl1/bl1_main.c') diff --git a/bl1/bl1_main.c b/bl1/bl1_main.c index cd6fe7d5e..bff8d22f5 100644 --- a/bl1/bl1_main.c +++ b/bl1/bl1_main.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2019, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -26,7 +26,7 @@ /* BL1 Service UUID */ DEFINE_SVC_UUID2(bl1_svc_uid, - 0xd46739fd, 0xcb72, 0x9a4d, 0xb5, 0x75, + U(0xd46739fd), 0xcb72, 0x9a4d, 0xb5, 0x75, 0x67, 0x15, 0xd6, 0xf4, 0xbb, 0x4a); static void bl1_load_bl2(void); @@ -172,7 +172,7 @@ static void bl1_load_bl2(void) /* Get the image descriptor */ image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); - assert(image_desc); + assert(image_desc != NULL); /* Get the image info */ image_info = &image_desc->image_info; @@ -276,7 +276,7 @@ register_t bl1_smc_wrapper(uint32_t smc_fid, { register_t x1, x2, x3, x4; - assert(handle); + assert(handle != NULL); get_smc_params_from_ctx(handle, x1, x2, x3, x4); return bl1_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags); -- cgit v1.2.3 From 2fe75a2de087ec23162c5fd25ba439bd330ea50c Mon Sep 17 00:00:00 2001 From: Zelalem Date: Wed, 12 Feb 2020 10:37:03 -0600 Subject: coverity: fix MISRA violations Fixes for the following MISRA violations: - Missing explicit parentheses on sub-expression - An identifier or macro name beginning with an underscore, shall not be declared - Type mismatch in BL1 SMC handlers and tspd_main.c Change-Id: I7a92abf260da95acb0846b27c2997b59b059efc4 Signed-off-by: Zelalem --- bl1/bl1_main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'bl1/bl1_main.c') diff --git a/bl1/bl1_main.c b/bl1/bl1_main.c index bff8d22f5..e11ead608 100644 --- a/bl1/bl1_main.c +++ b/bl1/bl1_main.c @@ -226,11 +226,11 @@ void print_debug_loop_message(void) /******************************************************************************* * Top level handler for servicing BL1 SMCs. ******************************************************************************/ -register_t bl1_smc_handler(unsigned int smc_fid, - register_t x1, - register_t x2, - register_t x3, - register_t x4, +u_register_t bl1_smc_handler(unsigned int smc_fid, + u_register_t x1, + u_register_t x2, + u_register_t x3, + u_register_t x4, void *cookie, void *handle, unsigned int flags) @@ -269,12 +269,12 @@ register_t bl1_smc_handler(unsigned int smc_fid, * BL1 SMC wrapper. This function is only used in AArch32 mode to ensure ABI * compliance when invoking bl1_smc_handler. ******************************************************************************/ -register_t bl1_smc_wrapper(uint32_t smc_fid, +u_register_t bl1_smc_wrapper(uint32_t smc_fid, void *cookie, void *handle, unsigned int flags) { - register_t x1, x2, x3, x4; + u_register_t x1, x2, x3, x4; assert(handle != NULL); -- cgit v1.2.3 From 3443a7027d78a9ccebc6940f0a69300ec7c1ed44 Mon Sep 17 00:00:00 2001 From: John Powell Date: Fri, 20 Mar 2020 14:21:05 -0500 Subject: Fix MISRA C issues in BL1/BL2/BL31 Attempts to address MISRA compliance issues in BL1, BL2, and BL31 code. Mainly issues like not using boolean expressions in conditionals, conflicting variable names, ignoring return values without (void), adding explicit casts, etc. Change-Id: If1fa18ab621b9c374db73fa6eaa6f6e5e55c146a Signed-off-by: John Powell --- bl1/bl1_main.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'bl1/bl1_main.c') diff --git a/bl1/bl1_main.c b/bl1/bl1_main.c index e11ead608..1479a967b 100644 --- a/bl1/bl1_main.c +++ b/bl1/bl1_main.c @@ -90,8 +90,7 @@ void bl1_main(void) NOTICE("BL1: %s\n", version_string); NOTICE("BL1: %s\n", build_message); - INFO("BL1: RAM %p - %p\n", (void *)BL1_RAM_BASE, - (void *)BL1_RAM_LIMIT); + INFO("BL1: RAM %p - %p\n", (void *)BL1_RAM_BASE, (void *)BL1_RAM_LIMIT); print_errata_status(); @@ -105,9 +104,9 @@ void bl1_main(void) #else val = read_sctlr(); #endif - assert(val & SCTLR_M_BIT); - assert(val & SCTLR_C_BIT); - assert(val & SCTLR_I_BIT); + assert((val & SCTLR_M_BIT) != 0); + assert((val & SCTLR_C_BIT) != 0); + assert((val & SCTLR_I_BIT) != 0); /* * Check that Cache Writeback Granule (CWG) in CTR_EL0 matches the * provided platform value @@ -166,33 +165,33 @@ void bl1_main(void) ******************************************************************************/ static void bl1_load_bl2(void) { - image_desc_t *image_desc; - image_info_t *image_info; + image_desc_t *desc; + image_info_t *info; int err; /* Get the image descriptor */ - image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); - assert(image_desc != NULL); + desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); + assert(desc != NULL); /* Get the image info */ - image_info = &image_desc->image_info; + info = &desc->image_info; INFO("BL1: Loading BL2\n"); err = bl1_plat_handle_pre_image_load(BL2_IMAGE_ID); - if (err) { + if (err != 0) { ERROR("Failure in pre image load handling of BL2 (%d)\n", err); plat_error_handler(err); } - err = load_auth_image(BL2_IMAGE_ID, image_info); - if (err) { + err = load_auth_image(BL2_IMAGE_ID, info); + if (err != 0) { ERROR("Failed to load BL2 firmware.\n"); plat_error_handler(err); } /* Allow platform to handle image information. */ err = bl1_plat_handle_post_image_load(BL2_IMAGE_ID); - if (err) { + if (err != 0) { ERROR("Failure in post image load handling of BL2 (%d)\n", err); plat_error_handler(err); } @@ -258,11 +257,9 @@ u_register_t bl1_smc_handler(unsigned int smc_fid, SMC_RET1(handle, BL1_SMC_MAJOR_VER | BL1_SMC_MINOR_VER); default: - break; + WARN("Unimplemented BL1 SMC Call: 0x%x\n", smc_fid); + SMC_RET1(handle, SMC_UNK); } - - WARN("Unimplemented BL1 SMC Call: 0x%x \n", smc_fid); - SMC_RET1(handle, SMC_UNK); } /******************************************************************************* -- cgit v1.2.3 From a14988c6613d396293fd13eb052178a7e8e0d036 Mon Sep 17 00:00:00 2001 From: Jimmy Brisson Date: Tue, 4 Aug 2020 16:27:51 -0500 Subject: Move static vars into functions in bl1 This reduces the scope of these variables and resolves Misra violations such as: bl1/aarch64/bl1_context_mgmt.c:21:[MISRA C-2012 Rule 8.9 (advisory)] "bl1_cpu_context" should be defined at block scope. Signed-off-by: Jimmy Brisson Change-Id: I9b0b26395bce07e10e61d10158c67f9c22ecce44 --- bl1/bl1_main.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'bl1/bl1_main.c') diff --git a/bl1/bl1_main.c b/bl1/bl1_main.c index 1479a967b..fd602324f 100644 --- a/bl1/bl1_main.c +++ b/bl1/bl1_main.c @@ -24,11 +24,6 @@ #include "bl1_private.h" -/* BL1 Service UUID */ -DEFINE_SVC_UUID2(bl1_svc_uid, - U(0xd46739fd), 0xcb72, 0x9a4d, 0xb5, 0x75, - 0x67, 0x15, 0xd6, 0xf4, 0xbb, 0x4a); - static void bl1_load_bl2(void); #if ENABLE_PAUTH @@ -234,6 +229,11 @@ u_register_t bl1_smc_handler(unsigned int smc_fid, void *handle, unsigned int flags) { + /* BL1 Service UUID */ + DEFINE_SVC_UUID2(bl1_svc_uid, + U(0xd46739fd), 0xcb72, 0x9a4d, 0xb5, 0x75, + 0x67, 0x15, 0xd6, 0xf4, 0xbb, 0x4a); + #if TRUSTED_BOARD_BOOT /* -- cgit v1.2.3