arm-trusted-firmware/lib/psci/psci_mem_protect.c
Antonio Nino Diaz 8c20c3c987 PSCI: Fix MISRA defects in MEM_PROTECT
MISRA C-2012 Rules 10.1 and 10.3.

Change-Id: I88cd5f56cda5780f2e0ba541c0f5b561309ab3af
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
2018-07-24 09:19:22 +01:00

39 lines
1,006 B
C

/*
* Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <assert.h>
#include <limits.h>
#include <utils.h>
#include "psci_private.h"
u_register_t psci_mem_protect(unsigned int enable)
{
int val;
assert(psci_plat_pm_ops->read_mem_protect != NULL);
assert(psci_plat_pm_ops->write_mem_protect != NULL);
if (psci_plat_pm_ops->read_mem_protect(&val) < 0)
return (u_register_t) PSCI_E_NOT_SUPPORTED;
if (psci_plat_pm_ops->write_mem_protect(enable) < 0)
return (u_register_t) PSCI_E_NOT_SUPPORTED;
return (val != 0) ? 1U : 0U;
}
u_register_t psci_mem_chk_range(uintptr_t base, u_register_t length)
{
int ret;
assert(psci_plat_pm_ops->mem_protect_chk != NULL);
if ((length == 0U) || check_uptr_overflow(base, length - 1U))
return (u_register_t) PSCI_E_DENIED;
ret = psci_plat_pm_ops->mem_protect_chk(base, length);
return (ret < 0) ?
(u_register_t) PSCI_E_DENIED : (u_register_t) PSCI_E_SUCCESS;
}