Commit 466bb285 authored by Zelalem's avatar Zelalem
Browse files

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: default avatarZelalem <zelalem.aweke@arm.com>
parent 235c8174
/* /*
* Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -69,7 +69,7 @@ void bl1_prepare_next_image(unsigned int image_id) ...@@ -69,7 +69,7 @@ void bl1_prepare_next_image(unsigned int image_id)
security_state = GET_SECURITY_STATE(next_bl_ep->h.attr); security_state = GET_SECURITY_STATE(next_bl_ep->h.attr);
/* Setup the Secure/Non-Secure context if not done already. */ /* Setup the Secure/Non-Secure context if not done already. */
if (!cm_get_context(security_state)) if (cm_get_context(security_state) == NULL)
cm_set_context(&bl1_cpu_context[security_state], security_state); cm_set_context(&bl1_cpu_context[security_state], security_state);
/* Prepare the SPSR for the next BL image. */ /* Prepare the SPSR for the next BL image. */
......
/* /*
* 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 * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
/* BL1 Service UUID */ /* BL1 Service UUID */
DEFINE_SVC_UUID2(bl1_svc_uid, DEFINE_SVC_UUID2(bl1_svc_uid,
0xd46739fd, 0xcb72, 0x9a4d, 0xb5, 0x75, U(0xd46739fd), 0xcb72, 0x9a4d, 0xb5, 0x75,
0x67, 0x15, 0xd6, 0xf4, 0xbb, 0x4a); 0x67, 0x15, 0xd6, 0xf4, 0xbb, 0x4a);
static void bl1_load_bl2(void); static void bl1_load_bl2(void);
...@@ -172,7 +172,7 @@ static void bl1_load_bl2(void) ...@@ -172,7 +172,7 @@ static void bl1_load_bl2(void)
/* Get the image descriptor */ /* Get the image descriptor */
image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID); image_desc = bl1_plat_get_image_desc(BL2_IMAGE_ID);
assert(image_desc); assert(image_desc != NULL);
/* Get the image info */ /* Get the image info */
image_info = &image_desc->image_info; image_info = &image_desc->image_info;
...@@ -276,7 +276,7 @@ register_t bl1_smc_wrapper(uint32_t smc_fid, ...@@ -276,7 +276,7 @@ register_t bl1_smc_wrapper(uint32_t smc_fid,
{ {
register_t x1, x2, x3, x4; register_t x1, x2, x3, x4;
assert(handle); assert(handle != NULL);
get_smc_params_from_ctx(handle, x1, x2, x3, x4); get_smc_params_from_ctx(handle, x1, x2, x3, x4);
return bl1_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags); return bl1_smc_handler(smc_fid, x1, x2, x3, x4, cookie, handle, flags);
......
/* /*
* Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -35,13 +35,13 @@ struct entry_point_info *bl2_load_images(void) ...@@ -35,13 +35,13 @@ struct entry_point_info *bl2_load_images(void)
* Get information about the images to load. * Get information about the images to load.
*/ */
bl2_load_info = plat_get_bl_image_load_info(); bl2_load_info = plat_get_bl_image_load_info();
assert(bl2_load_info); assert(bl2_load_info != NULL);
assert(bl2_load_info->head); assert(bl2_load_info->head != NULL);
assert(bl2_load_info->h.type == PARAM_BL_LOAD_INFO); assert(bl2_load_info->h.type == PARAM_BL_LOAD_INFO);
assert(bl2_load_info->h.version >= VERSION_2); assert(bl2_load_info->h.version >= VERSION_2);
bl2_node_info = bl2_load_info->head; bl2_node_info = bl2_load_info->head;
while (bl2_node_info) { while (bl2_node_info != NULL) {
/* /*
* Perform platform setup before loading the image, * Perform platform setup before loading the image,
* if indicated in the image attributes AND if NOT * if indicated in the image attributes AND if NOT
...@@ -91,11 +91,11 @@ struct entry_point_info *bl2_load_images(void) ...@@ -91,11 +91,11 @@ struct entry_point_info *bl2_load_images(void)
* Get information to pass to the next image. * Get information to pass to the next image.
*/ */
bl2_to_next_bl_params = plat_get_next_bl_params(); bl2_to_next_bl_params = plat_get_next_bl_params();
assert(bl2_to_next_bl_params); assert(bl2_to_next_bl_params != NULL);
assert(bl2_to_next_bl_params->head); assert(bl2_to_next_bl_params->head != NULL);
assert(bl2_to_next_bl_params->h.type == PARAM_BL_PARAMS); assert(bl2_to_next_bl_params->h.type == PARAM_BL_PARAMS);
assert(bl2_to_next_bl_params->h.version >= VERSION_2); assert(bl2_to_next_bl_params->h.version >= VERSION_2);
assert(bl2_to_next_bl_params->head->ep_info); assert(bl2_to_next_bl_params->head->ep_info != NULL);
/* Populate arg0 for the next BL image if not already provided */ /* Populate arg0 for the next BL image if not already provided */
if (bl2_to_next_bl_params->head->ep_info->args.arg0 == (u_register_t)0) if (bl2_to_next_bl_params->head->ep_info->args.arg0 == (u_register_t)0)
......
/* /*
* Copyright (c) 2016-2019, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2016-2020, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -301,9 +301,9 @@ void bl31_params_parse_helper(u_register_t param, ...@@ -301,9 +301,9 @@ void bl31_params_parse_helper(u_register_t param,
image_info_t *bl33_image_info; image_info_t *bl33_image_info;
} *v1 = (void *)(uintptr_t)param; } *v1 = (void *)(uintptr_t)param;
assert(v1->h.type == PARAM_BL31); assert(v1->h.type == PARAM_BL31);
if (bl32_ep_info_out) if (bl32_ep_info_out != NULL)
*bl32_ep_info_out = *v1->bl32_ep_info; *bl32_ep_info_out = *v1->bl32_ep_info;
if (bl33_ep_info_out) if (bl33_ep_info_out != NULL)
*bl33_ep_info_out = *v1->bl33_ep_info; *bl33_ep_info_out = *v1->bl33_ep_info;
return; return;
} }
...@@ -311,12 +311,12 @@ void bl31_params_parse_helper(u_register_t param, ...@@ -311,12 +311,12 @@ void bl31_params_parse_helper(u_register_t param,
assert(v2->h.version == PARAM_VERSION_2); assert(v2->h.version == PARAM_VERSION_2);
assert(v2->h.type == PARAM_BL_PARAMS); assert(v2->h.type == PARAM_BL_PARAMS);
for (node = v2->head; node; node = node->next_params_info) { for (node = v2->head; node != NULL; node = node->next_params_info) {
if (node->image_id == BL32_IMAGE_ID) if (node->image_id == BL32_IMAGE_ID)
if (bl32_ep_info_out) if (bl32_ep_info_out != NULL)
*bl32_ep_info_out = *node->ep_info; *bl32_ep_info_out = *node->ep_info;
if (node->image_id == BL33_IMAGE_ID) if (node->image_id == BL33_IMAGE_ID)
if (bl33_ep_info_out) if (bl33_ep_info_out != NULL)
*bl33_ep_info_out = *node->ep_info; *bl33_ep_info_out = *node->ep_info;
} }
} }
/* /*
* Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2018-2020, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -90,7 +90,7 @@ int console_putc(int c) ...@@ -90,7 +90,7 @@ int console_putc(int c)
console_t *console; console_t *console;
for (console = console_list; console != NULL; console = console->next) for (console = console_list; console != NULL; console = console->next)
if ((console->flags & console_state) && console->putc) { if ((console->flags & console_state) && (console->putc != NULL)) {
int ret = do_putc(c, console); int ret = do_putc(c, console);
if ((err == ERROR_NO_VALID_CONSOLE) || (ret < err)) if ((err == ERROR_NO_VALID_CONSOLE) || (ret < err))
err = ret; err = ret;
...@@ -107,7 +107,7 @@ int console_getc(void) ...@@ -107,7 +107,7 @@ int console_getc(void)
do { /* Keep polling while at least one console works correctly. */ do { /* Keep polling while at least one console works correctly. */
for (console = console_list; console != NULL; for (console = console_list; console != NULL;
console = console->next) console = console->next)
if ((console->flags & console_state) && console->getc) { if ((console->flags & console_state) && (console->getc != NULL)) {
int ret = console->getc(console); int ret = console->getc(console);
if (ret >= 0) if (ret >= 0)
return ret; return ret;
...@@ -125,7 +125,7 @@ int console_flush(void) ...@@ -125,7 +125,7 @@ int console_flush(void)
console_t *console; console_t *console;
for (console = console_list; console != NULL; console = console->next) for (console = console_list; console != NULL; console = console->next)
if ((console->flags & console_state) && console->flush) { if ((console->flags & console_state) && (console->flush != NULL)) {
int ret = console->flush(console); int ret = console->flush(console);
if ((err == ERROR_NO_VALID_CONSOLE) || (ret < err)) if ((err == ERROR_NO_VALID_CONSOLE) || (ret < err))
err = ret; err = ret;
......
/* /*
* Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2017-2020, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -32,7 +32,7 @@ void clear_mem_regions(mem_region_t *tbl, size_t nregions) ...@@ -32,7 +32,7 @@ void clear_mem_regions(mem_region_t *tbl, size_t nregions)
{ {
size_t i; size_t i;
assert(tbl); assert(tbl != NULL);
assert(nregions > 0); assert(nregions > 0);
for (i = 0; i < nregions; i++) { for (i = 0; i < nregions; i++) {
...@@ -114,7 +114,7 @@ int mem_region_in_array_chk(mem_region_t *tbl, size_t nregions, ...@@ -114,7 +114,7 @@ int mem_region_in_array_chk(mem_region_t *tbl, size_t nregions,
uintptr_t region_start, region_end, start, end; uintptr_t region_start, region_end, start, end;
size_t i; size_t i;
assert(tbl); assert(tbl != NULL);
assert(nbytes > 0); assert(nbytes > 0);
assert(!check_uptr_overflow(addr, nbytes-1)); assert(!check_uptr_overflow(addr, nbytes-1));
......
/* /*
* Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2015-2020, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -150,7 +150,7 @@ int arm_bl2_handle_post_image_load(unsigned int image_id) ...@@ -150,7 +150,7 @@ int arm_bl2_handle_post_image_load(unsigned int image_id)
bl_mem_params_node_t *pager_mem_params = NULL; bl_mem_params_node_t *pager_mem_params = NULL;
bl_mem_params_node_t *paged_mem_params = NULL; bl_mem_params_node_t *paged_mem_params = NULL;
#endif #endif
assert(bl_mem_params); assert(bl_mem_params != NULL);
switch (image_id) { switch (image_id) {
#ifdef __aarch64__ #ifdef __aarch64__
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment