drivers: renesas: rcar: io: Code cleanup

This patch fixes checkpatch warnings and arrange header
as per TF-A coding style.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Reviewed-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Change-Id: I46cd4d9b2851202324fe714e776cf3ad2ee1d923
diff --git a/drivers/renesas/rcar/io/io_rcar.c b/drivers/renesas/rcar/io/io_rcar.c
index b82c510..c3e8319 100644
--- a/drivers/renesas/rcar/io/io_rcar.c
+++ b/drivers/renesas/rcar/io/io_rcar.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015-2018, Renesas Electronics Corporation. All rights reserved.
+ * Copyright (c) 2015-2021, Renesas Electronics Corporation. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  */
@@ -8,8 +8,6 @@
 #include <stdint.h>
 #include <string.h>
 
-#include <platform_def.h>
-
 #include <arch_helpers.h>
 #include <common/bl_common.h>
 #include <common/debug.h>
@@ -24,6 +22,7 @@
 #include "io_rcar.h"
 #include "io_common.h"
 #include "io_private.h"
+#include <platform_def.h>
 
 extern int32_t plat_get_drv_source(uint32_t id, uintptr_t *dev,
 				   uintptr_t *image_spec);
@@ -39,7 +38,8 @@
 } plat_rcar_name_offset_t;
 
 typedef struct {
-	/* Put position above the struct to allow {0} on static init.
+	/*
+	 * Put position above the struct to allow {0} on static init.
 	 * It is a workaround for a known bug in GCC
 	 * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53119
 	 */
@@ -59,7 +59,7 @@
 #define RCAR_ATTR_SET_ISNOLOAD(a)	(((a) & 0x1) << 16U)
 #define RCAR_ATTR_SET_CERTOFF(a)	(((a) & 0xF) << 8U)
 #define RCAR_ATTR_SET_ALL(a, b, c)	((uint32_t)(RCAR_ATTR_SET_CALCADDR(a) |\
-					RCAR_ATTR_SET_ISNOLOAD(b) | 	\
+					RCAR_ATTR_SET_ISNOLOAD(b) |\
 					RCAR_ATTR_SET_CERTOFF(c)))
 
 #define RCAR_ATTR_GET_CALCADDR(a)	((a) & 0xFU)
@@ -136,9 +136,11 @@
 {
 #if TRUSTED_BOARD_BOOT
 	int32_t i;
+
 	for (i = 0; i < ARRAY_SIZE(cert_offset); i++) {
-		if (name != cert_offset[i].name)
+		if (name != cert_offset[i].name) {
 			continue;
+		}
 
 		*cert = RCAR_CERT_SIZE;
 		*cert *= RCAR_ATTR_GET_CERTOFF(cert_offset[i].attr);
@@ -157,12 +159,14 @@
 	int32_t i;
 
 	for (i = 0; i < ARRAY_SIZE(name_offset); i++) {
-		if (name != name_offset[i].name)
+		if (name != name_offset[i].name) {
 			continue;
+		}
 
 		addr = RCAR_ATTR_GET_CALCADDR(name_offset[i].attr);
-		if (rcar_image_number + 2 < addr)
+		if (rcar_image_number + 2U < addr) {
 			continue;
+		}
 
 		*offset = rcar_image_header[addr];
 		*cert = RCAR_CERT_SIZE;
@@ -175,8 +179,9 @@
 
 #if TRUSTED_BOARD_BOOT
 	for (i = 0; i < ARRAY_SIZE(cert_offset); i++) {
-		if (name != cert_offset[i].name)
+		if (name != cert_offset[i].name) {
 			continue;
+		}
 
 		*no_load = RCAR_ATTR_GET_ISNOLOAD(cert_offset[i].attr);
 		*partition = 0U;
@@ -282,8 +287,9 @@
 		result = IO_FAIL;
 	}
 done:
-	if (result == IO_FAIL)
+	if (result == IO_FAIL) {
 		ERROR("BL2: Out of range : dst=0x%lx len=0x%lx\n", dst, len);
+	}
 
 	return result;
 }
@@ -307,14 +313,15 @@
 		BL338_IMAGE_ID
 	};
 
-	if (loaded != IO_NOT_SUPPORTED)
+	if (loaded != IO_NOT_SUPPORTED) {
 		return loaded;
+	}
 
 	for (i = 1; i < rcar_image_number; i++) {
 		rc = file_to_offset(img[i], &offset, &cert, &noload,
 				    &partition);
 		if (rc != IO_SUCCESS) {
-			WARN("load_bl33x: failed to get offset\n");
+			WARN("%s: failed to get offset\n", __func__);
 			loaded = IO_FAIL;
 			return loaded;
 		}
@@ -324,34 +331,34 @@
 
 		rc = io_open(rcar_handle, rcar_spec, &handle);
 		if (rc != IO_SUCCESS) {
-			WARN("Failed to open FIP (%i)\n", rc);
+			WARN("%s: Failed to open FIP (%i)\n", __func__, rc);
 			loaded = IO_FAIL;
 			return loaded;
 		}
 
 		rc = io_seek(handle, IO_SEEK_SET, offset);
 		if (rc != IO_SUCCESS) {
-			WARN("load_bl33x: failed to seek\n");
+			WARN("%s: failed to seek\n", __func__);
 			loaded = IO_FAIL;
 			return loaded;
 		}
 
 		rc = check_load_area(dst, len);
 		if (rc != IO_SUCCESS) {
-			WARN("load_bl33x: check load area\n");
+			WARN("%s: check load area\n", __func__);
 			loaded = IO_FAIL;
 			return loaded;
 		}
 
 		rc = io_read(handle, dst, len, &cnt);
 		if (rc != IO_SUCCESS) {
-			WARN("load_bl33x: failed to read\n");
+			WARN("%s: failed to read\n", __func__);
 			loaded = IO_FAIL;
 			return loaded;
 		}
 #if TRUSTED_BOARD_BOOT
 		rc = auth_mod_verify_img(img[i], (void *)dst, len);
-		if (rc) {
+		if (rc != 0) {
 			memset((void *)dst, 0x00, len);
 			loaded = IO_FAIL;
 			return loaded;
@@ -367,8 +374,7 @@
 
 static int32_t rcar_dev_init(io_dev_info_t *dev_info, const uintptr_t name)
 {
-	uint64_t header[64] __aligned(FLASH_TRANS_SIZE_UNIT) = {
-	0};
+	uint64_t header[64] __aligned(FLASH_TRANS_SIZE_UNIT) = {0UL};
 	uintptr_t handle;
 	ssize_t offset;
 	uint32_t i;
@@ -382,8 +388,9 @@
 		return IO_FAIL;
 	}
 
-	if (RCAR_CERT_LOAD == rcar_cert_load)
+	if (rcar_cert_load == RCAR_CERT_LOAD) {
 		return IO_SUCCESS;
+	}
 
 	rc = io_open(rcar_handle, rcar_spec, &handle);
 	if (rc != IO_SUCCESS) {
@@ -391,16 +398,18 @@
 		return IO_FAIL;
 	}
 
-	/* get start address list   */
-	/* [0] address num          */
-	/* [1] BL33-1 image address */
-	/* [2] BL33-2 image address */
-	/* [3] BL33-3 image address */
-	/* [4] BL33-4 image address */
-	/* [5] BL33-5 image address */
-	/* [6] BL33-6 image address */
-	/* [7] BL33-7 image address */
-	/* [8] BL33-8 image address */
+	/*
+	 * get start address list
+	 * [0] address num
+	 * [1] BL33-1 image address
+	 * [2] BL33-2 image address
+	 * [3] BL33-3 image address
+	 * [4] BL33-4 image address
+	 * [5] BL33-5 image address
+	 * [6] BL33-6 image address
+	 * [7] BL33-7 image address
+	 * [8] BL33-8 image address
+	 */
 	offset = name == EMMC_DEV_ID ? RCAR_EMMC_CERT_HEADER :
 	    RCAR_FLASH_CERT_HEADER;
 	rc = io_seek(handle, IO_SEEK_SET, offset);
@@ -447,8 +456,9 @@
 	rcar_cert_load = RCAR_CERT_LOAD;
 error:
 
-	if (rc != IO_SUCCESS)
+	if (rc != IO_SUCCESS) {
 		rc = IO_FAIL;
+	}
 
 	io_close(handle);
 
@@ -464,13 +474,15 @@
 	uint32_t noload, cert, len;
 	int32_t rc;
 
-	/* Only one file open at a time. We need to  track state (ie, file
-	 * cursor position). Since the header lives at * offset zero, this entry
+	/*
+	 * Only one file open at a time. We need to  track state (ie, file
+	 * cursor position). Since the header lives at offset zero, this entry
 	 * should never be zero in an active file.
 	 * Once the system supports dynamic memory allocation we will allow more
-	 * than one open file at a time. */
+	 * than one open file at a time.
+	 */
 	if (current_file.offset != 0U) {
-		WARN("rcar_file_open : Only one open file at a time.\n");
+		WARN("%s: Only one open file at a time.\n", __func__);
 		return IO_RESOURCES_EXHAUSTED;
 	}
 
@@ -480,7 +492,7 @@
 		return IO_FAIL;
 	}
 
-	if (noload) {
+	if (noload != 0U) {
 		current_file.offset = 1;
 		current_file.dst = 0;
 		current_file.size = 1;
@@ -494,12 +506,10 @@
 
 	rcar_read_certificate((uint64_t) cert, &len, &dst);
 
-	/*----------------*
-	 * Baylibre: HACK *
-	 *----------------*/
-	if (BL31_IMAGE_ID == spec->offset && len < RCAR_TRUSTED_SRAM_SIZE) {
-		WARN("r-car ignoring the BL31 size from certificate,"
-		     "using RCAR_TRUSTED_SRAM_SIZE instead\n");
+	/* Baylibre: HACK */
+	if (spec->offset == BL31_IMAGE_ID && len < RCAR_TRUSTED_SRAM_SIZE) {
+		WARN("%s,%s\n", "r-car ignoring the BL31 size from certificate",
+		     "using RCAR_TRUSTED_SRAM_SIZE instead");
 		len = RCAR_TRUSTED_SRAM_SIZE;
 	}
 
@@ -536,7 +546,7 @@
 #else
 	static uint32_t load_bl33x_counter;
 #endif
-	if (current_file.no_load) {
+	if (current_file.no_load != 0U) {
 		*cnt = length;
 		return IO_SUCCESS;
 	}
@@ -551,14 +561,14 @@
 
 	rc = io_seek(handle, IO_SEEK_SET, offset);
 	if (rc != IO_SUCCESS) {
-		WARN("rcar_file_read: failed to seek\n");
+		WARN("%s: failed to seek\n", __func__);
 		goto error;
 	}
 
 	if (load_bl33x_counter == RCAR_COUNT_LOAD_BL33) {
 		rc = check_load_area(buffer, length);
 		if (rc != IO_SUCCESS) {
-			WARN("rcar_file_read: load area err\n");
+			WARN("%s: load area err\n", __func__);
 			goto error;
 		}
 	}
@@ -573,8 +583,9 @@
 	io_close(handle);
 
 	load_bl33x_counter += 1;
-	if (load_bl33x_counter == RCAR_COUNT_LOAD_BL33X)
+	if (load_bl33x_counter == RCAR_COUNT_LOAD_BL33X) {
 		return load_bl33x();
+	}
 
 	return IO_SUCCESS;
 error:
@@ -584,8 +595,9 @@
 
 static int32_t rcar_file_close(io_entity_t *entity)
 {
-	if (current_file.offset)
+	if (current_file.offset != 0U) {
 		memset(&current_file, 0, sizeof(current_file));
+	}
 
 	entity->info = 0U;
 
@@ -634,8 +646,9 @@
 	int32_t result;
 
 	result = io_register_device(&rcar_dev_info);
-	if (result == IO_SUCCESS)
+	if (result == IO_SUCCESS) {
 		*dev_con = &rcar_dev_connector;
+	}
 
 	return result;
 }