drivers: cci: Fix MISRA defects

Change-Id: Ifdb0ceec19d267b14d796b5d31f08f7342190484
Signed-off-by: Antonio Nino Diaz <antonio.ninodiaz@arm.com>
diff --git a/drivers/arm/cci/cci.c b/drivers/arm/cci/cci.c
index a6ee77a..91245d4 100644
--- a/drivers/arm/cci/cci.c
+++ b/drivers/arm/cci/cci.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
+ * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -10,11 +10,12 @@
 #include <cci.h>
 #include <debug.h>
 #include <mmio.h>
+#include <stdbool.h>
 #include <stdint.h>
 
-#define MAKE_CCI_PART_NUMBER(hi, lo)	((hi << 8) | lo)
-#define CCI_PART_LO_MASK		0xff
-#define CCI_PART_HI_MASK		0xf
+#define MAKE_CCI_PART_NUMBER(hi, lo)	(((hi) << 8) | (lo))
+#define CCI_PART_LO_MASK		U(0xff)
+#define CCI_PART_HI_MASK		U(0xf)
 
 /* CCI part number codes read from Peripheral ID registers 0 and 1 */
 #define CCI400_PART_NUM		0x420
@@ -32,14 +33,14 @@
 static unsigned int max_master_id;
 static int cci_num_slave_ports;
 
-static int validate_cci_map(const int *map)
+static bool validate_cci_map(const int *map)
 {
-	unsigned int valid_cci_map = 0;
+	unsigned int valid_cci_map = 0U;
 	int slave_if_id;
-	int i;
+	unsigned int i;
 
 	/* Validate the map */
-	for (i = 0; i <= max_master_id; i++) {
+	for (i = 0U; i <= max_master_id; i++) {
 		slave_if_id = map[i];
 
 		if (slave_if_id < 0)
@@ -47,22 +48,22 @@
 
 		if (slave_if_id >= cci_num_slave_ports) {
 			ERROR("Slave interface ID is invalid\n");
-			return 0;
+			return false;
 		}
 
-		if (valid_cci_map & (1 << slave_if_id)) {
+		if ((valid_cci_map & (1U << slave_if_id)) != 0U) {
 			ERROR("Multiple masters are assigned same slave interface ID\n");
-			return 0;
+			return false;
 		}
-		valid_cci_map |= 1 << slave_if_id;
+		valid_cci_map |= 1U << slave_if_id;
 	}
 
-	if (!valid_cci_map) {
+	if (valid_cci_map == 0U) {
 		ERROR("No master is assigned a valid slave interface\n");
-		return 0;
+		return false;
 	}
 
-	return 1;
+	return true;
 }
 
 /*
@@ -108,8 +109,8 @@
 
 void cci_init(uintptr_t base, const int *map, unsigned int num_cci_masters)
 {
-	assert(map);
-	assert(base);
+	assert(map != NULL);
+	assert(base != 0U);
 
 	cci_base = base;
 	cci_slave_if_map = map;
@@ -119,7 +120,7 @@
 	 * Master Id's are assigned from zero, So in an array of size n
 	 * the max master id is (n - 1).
 	 */
-	max_master_id = num_cci_masters - 1;
+	max_master_id = num_cci_masters - 1U;
 	cci_num_slave_ports = get_slave_ports(read_cci_part_number(base));
 #endif
 	assert(cci_num_slave_ports >= 0);
@@ -133,7 +134,7 @@
 
 	assert(master_id <= max_master_id);
 	assert((slave_if_id < cci_num_slave_ports) && (slave_if_id >= 0));
-	assert(cci_base);
+	assert(cci_base != 0U);
 
 	/*
 	 * Enable Snoops and DVM messages, no need for Read/Modify/Write as
@@ -150,7 +151,7 @@
 	dsbish();
 
 	/* Wait for the dust to settle down */
-	while (mmio_read_32(cci_base + STATUS_REG) & CHANGE_PENDING_BIT)
+	while ((mmio_read_32(cci_base + STATUS_REG) & CHANGE_PENDING_BIT) != 0U)
 		;
 }
 
@@ -160,7 +161,7 @@
 
 	assert(master_id <= max_master_id);
 	assert((slave_if_id < cci_num_slave_ports) && (slave_if_id >= 0));
-	assert(cci_base);
+	assert(cci_base != 0U);
 
 	/*
 	 * Disable Snoops and DVM messages, no need for Read/Modify/Write as
@@ -177,7 +178,7 @@
 	dsbish();
 
 	/* Wait for the dust to settle down */
-	while (mmio_read_32(cci_base + STATUS_REG) & CHANGE_PENDING_BIT)
+	while ((mmio_read_32(cci_base + STATUS_REG) & CHANGE_PENDING_BIT) != 0U)
 		;
 }