1From da003e6ada7d0217fe99dc7c649a731f8ebd3c34 Mon Sep 17 00:00:00 2001
2From: Deepika Bhavnani <deepika.bhavnani@arm.com>
3Date: Thu, 15 Aug 2019 00:56:46 +0300
4Subject: [PATCH] Coverity fix: Remove GGC ignore -Warray-bounds
5
6GCC diagnostics were added to ignore array boundaries, instead
7of ignoring GCC warning current code will check for array boundaries
8and perform and array update only for valid elements.
9
10Resolves: `CID 246574` `CID 246710` `CID 246651`
11
12Signed-off-by: Deepika Bhavnani <deepika.bhavnani@arm.com>
13Change-Id: I7530ecf7a1707351c6ee87e90cc3d33574088f57
14
15Backported from: 41af05154abe136938bcfb5f26c969933784bbef
16[Adapted to apply on 1.5]
17
18---
19 lib/psci/psci_common.c | 20 ++++++++++----------
20 1 file changed, 10 insertions(+), 10 deletions(-)
21
22diff --git a/lib/psci/psci_common.c b/lib/psci/psci_common.c
23index 2220a745cd6e..6282d992a2f0 100644
24--- a/lib/psci/psci_common.c
25+++ b/lib/psci/psci_common.c
26@@ -188,21 +188,17 @@ static unsigned int get_power_on_target_pwrlvl(void)
27 /******************************************************************************
28  * Helper function to update the requested local power state array. This array
29  * does not store the requested state for the CPU power level. Hence an
30- * assertion is added to prevent us from accessing the wrong index.
31+ * assertion is added to prevent us from accessing the CPU power level.
32  *****************************************************************************/
33 static void psci_set_req_local_pwr_state(unsigned int pwrlvl,
34 					 unsigned int cpu_idx,
35 					 plat_local_state_t req_pwr_state)
36 {
37-	/*
38-	 * This should never happen, we have this here to avoid
39-	 * "array subscript is above array bounds" errors in GCC.
40-	 */
41 	assert(pwrlvl > PSCI_CPU_PWR_LVL);
42-#pragma GCC diagnostic push
43-#pragma GCC diagnostic ignored "-Warray-bounds"
44-	psci_req_local_pwr_states[pwrlvl - 1][cpu_idx] = req_pwr_state;
45-#pragma GCC diagnostic pop
46+	if ((pwrlvl > PSCI_CPU_PWR_LVL) && (pwrlvl <= PLAT_MAX_PWR_LVL) &&
47+			(cpu_idx < PLATFORM_CORE_COUNT)) {
48+		psci_req_local_pwr_states[pwrlvl - 1U][cpu_idx] = req_pwr_state;
49+	}
50 }
51
52 /******************************************************************************
53@@ -228,7 +224,11 @@ static plat_local_state_t *psci_get_req_local_pwr_states(unsigned int pwrlvl,
54 {
55 	assert(pwrlvl > PSCI_CPU_PWR_LVL);
56
57-	return &psci_req_local_pwr_states[pwrlvl - 1][cpu_idx];
58+	if ((pwrlvl > PSCI_CPU_PWR_LVL) && (pwrlvl <= PLAT_MAX_PWR_LVL) &&
59+			(cpu_idx < PLATFORM_CORE_COUNT)) {
60+		return &psci_req_local_pwr_states[pwrlvl - 1U][cpu_idx];
61+	} else
62+		return NULL;
63 }
64
65 /*
66--
672.34.0
68
69