From 1ed51c56ddf97da3e9f5ce7d22666c05ce823d97 Mon Sep 17 00:00:00 2001 From: Nicola Mazzucato Date: Fri, 11 Jan 2019 14:40:35 +0000 Subject: [PATCH] clark: Fix GCC 7 -Wformat-truncation error GCC 7 introduces the -Wformat-truncation warning and associated heuristics. This warning identifies potentially unexpected string truncation issues by statically range-checking the vararg inputs to snprintf(). For us, GCC seems to be unable to reliably identify the bounds of the inputs (cluster_idx, core_idx) even though we have static guarantees in place as those guarantees are made in a separate compilation unit from the one in which the error occurs. This patch allows the compiler to inline the cluster/core count functions to ensure it can properly ascertain the proper bounds on the inputs to snprintf(). Change-Id: Ie332561573d33a38063863fa7a4423c0c82543c4 Signed-off-by: Nicola Mazzucato --- product/clark/include/clark_core.h | 26 +++++++++++++++++++++--- product/clark/scp_ramfw/firmware.mk | 1 - product/clark/src/clark_core.c | 31 ----------------------------- 3 files changed, 23 insertions(+), 35 deletions(-) delete mode 100644 product/clark/src/clark_core.c diff --git a/product/clark/include/clark_core.h b/product/clark/include/clark_core.h index 3cd141028..bfda3730e 100644 --- a/product/clark/include/clark_core.h +++ b/product/clark/include/clark_core.h @@ -8,10 +8,30 @@ #ifndef CLARK_CORE_H #define CLARK_CORE_H +#include + #define CLARK_CORE_PER_CLUSTER_MAX 8 -unsigned int clark_core_get_core_per_cluster_count(unsigned int cluster); -unsigned int clark_core_get_core_count(void); -unsigned int clark_core_get_cluster_count(void); +/* Clark only has one configuration, hence the constant values */ +#define CORES_PER_CLUSTER 4 +#define NUMBER_OF_CLUSTERS 2 + +static inline unsigned int clark_core_get_cluster_count(void) +{ + return NUMBER_OF_CLUSTERS; +} + +static inline unsigned int clark_core_get_core_per_cluster_count( + unsigned int cluster) +{ + fwk_assert(cluster < clark_core_get_cluster_count()); + + return CORES_PER_CLUSTER; +} + +static inline unsigned int clark_core_get_core_count(void) +{ + return NUMBER_OF_CLUSTERS * CORES_PER_CLUSTER; +} #endif /* CLARK_CORE_H */ diff --git a/product/clark/scp_ramfw/firmware.mk b/product/clark/scp_ramfw/firmware.mk index 8a678bbe0..25bc3109a 100644 --- a/product/clark/scp_ramfw/firmware.mk +++ b/product/clark/scp_ramfw/firmware.mk @@ -50,7 +50,6 @@ BS_FIRMWARE_SOURCES := \ config_system_power.c \ config_sid.c \ rtx_config.c \ - clark_core.c \ config_armv7m_mpu.c \ config_log.c \ config_power_domain.c \ diff --git a/product/clark/src/clark_core.c b/product/clark/src/clark_core.c deleted file mode 100644 index 84cf7b10c..000000000 --- a/product/clark/src/clark_core.c +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Arm SCP/MCP Software - * Copyright (c) 2017-2019, Arm Limited and Contributors. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -#include -#include - -/* Clark only has one configuration, hence the constant values */ - -#define CORES_PER_CLUSTER 4 -#define NUMBER_OF_CLUSTERS 2 - -unsigned int clark_core_get_core_per_cluster_count(unsigned int cluster) -{ - assert(cluster < clark_core_get_cluster_count()); - - return CORES_PER_CLUSTER; -} - -unsigned int clark_core_get_core_count(void) -{ - return NUMBER_OF_CLUSTERS * CORES_PER_CLUSTER; -} - -unsigned int clark_core_get_cluster_count(void) -{ - return NUMBER_OF_CLUSTERS; -} -- GitLab