Commit 8c20c3c9 authored by Antonio Nino Diaz's avatar Antonio Nino Diaz
Browse files

PSCI: Fix MISRA defects in MEM_PROTECT



MISRA C-2012 Rules 10.1 and 10.3.

Change-Id: I88cd5f56cda5780f2e0ba541c0f5b561309ab3af
Signed-off-by: default avatarAntonio Nino Diaz <antonio.ninodiaz@arm.com>
parent 621d64f8
/* /*
* Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
...@@ -9,30 +9,31 @@ ...@@ -9,30 +9,31 @@
#include <utils.h> #include <utils.h>
#include "psci_private.h" #include "psci_private.h"
int psci_mem_protect(unsigned int enable) u_register_t psci_mem_protect(unsigned int enable)
{ {
int val; int val;
assert(psci_plat_pm_ops->read_mem_protect); assert(psci_plat_pm_ops->read_mem_protect != NULL);
assert(psci_plat_pm_ops->write_mem_protect); assert(psci_plat_pm_ops->write_mem_protect != NULL);
if (psci_plat_pm_ops->read_mem_protect(&val) < 0) if (psci_plat_pm_ops->read_mem_protect(&val) < 0)
return PSCI_E_NOT_SUPPORTED; return (u_register_t) PSCI_E_NOT_SUPPORTED;
if (psci_plat_pm_ops->write_mem_protect(enable) < 0) if (psci_plat_pm_ops->write_mem_protect(enable) < 0)
return PSCI_E_NOT_SUPPORTED; return (u_register_t) PSCI_E_NOT_SUPPORTED;
return val != 0; return (val != 0) ? 1U : 0U;
} }
int psci_mem_chk_range(uintptr_t base, u_register_t length) u_register_t psci_mem_chk_range(uintptr_t base, u_register_t length)
{ {
int ret; int ret;
assert(psci_plat_pm_ops->mem_protect_chk); assert(psci_plat_pm_ops->mem_protect_chk != NULL);
if (length == 0 || check_uptr_overflow(base, length-1)) if ((length == 0U) || check_uptr_overflow(base, length - 1U))
return PSCI_E_DENIED; return (u_register_t) PSCI_E_DENIED;
ret = psci_plat_pm_ops->mem_protect_chk(base, length); ret = psci_plat_pm_ops->mem_protect_chk(base, length);
return (ret < 0) ? PSCI_E_DENIED : PSCI_E_SUCCESS; return (ret < 0) ?
(u_register_t) PSCI_E_DENIED : (u_register_t) PSCI_E_SUCCESS;
} }
...@@ -330,7 +330,7 @@ u_register_t psci_stat_count(u_register_t target_cpu, ...@@ -330,7 +330,7 @@ u_register_t psci_stat_count(u_register_t target_cpu,
unsigned int power_state); unsigned int power_state);
/* Private exported functions from psci_mem_protect.c */ /* Private exported functions from psci_mem_protect.c */
int psci_mem_protect(unsigned int enable); u_register_t psci_mem_protect(unsigned int enable);
int psci_mem_chk_range(uintptr_t base, u_register_t length); u_register_t psci_mem_chk_range(uintptr_t base, u_register_t length);
#endif /* PSCI_PRIVATE_H */ #endif /* PSCI_PRIVATE_H */
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