Merge pull request #222 from jbech-linaro/user_guide_toc_links

Create TOC links in the User Guide markdown file
diff --git a/plat/fvp/fvp_def.h b/plat/fvp/fvp_def.h
index 99c23d8..06f2a64 100644
--- a/plat/fvp/fvp_def.h
+++ b/plat/fvp/fvp_def.h
@@ -209,7 +209,6 @@
 #define IRQ_SEC_SGI_5			13
 #define IRQ_SEC_SGI_6			14
 #define IRQ_SEC_SGI_7			15
-#define IRQ_SEC_SGI_8			16
 
 /*******************************************************************************
  * PL011 related constants
diff --git a/plat/juno/juno_def.h b/plat/juno/juno_def.h
index 88e35b0..e205498 100644
--- a/plat/juno/juno_def.h
+++ b/plat/juno/juno_def.h
@@ -143,7 +143,6 @@
 #define IRQ_SEC_SGI_5			13
 #define IRQ_SEC_SGI_6			14
 #define IRQ_SEC_SGI_7			15
-#define IRQ_SEC_SGI_8			16
 
 /*******************************************************************************
  * PL011 related constants
diff --git a/services/std_svc/psci/psci_common.c b/services/std_svc/psci/psci_common.c
index 2267ad0..155f842 100644
--- a/services/std_svc/psci/psci_common.c
+++ b/services/std_svc/psci/psci_common.c
@@ -201,7 +201,7 @@
 int psci_check_afflvl_range(int start_afflvl, int end_afflvl)
 {
 	/* Sanity check the parameters passed */
-	if (end_afflvl > MPIDR_MAX_AFFLVL)
+	if (end_afflvl > get_max_afflvl())
 		return PSCI_E_INVALID_PARAMS;
 
 	if (start_afflvl < MPIDR_AFFLVL0)
diff --git a/services/std_svc/psci/psci_main.c b/services/std_svc/psci/psci_main.c
index 0ffa5d7..2e700e8 100644
--- a/services/std_svc/psci/psci_main.c
+++ b/services/std_svc/psci/psci_main.c
@@ -86,7 +86,7 @@
 
 	/* Sanity check the requested state */
 	target_afflvl = psci_get_pstate_afflvl(power_state);
-	if (target_afflvl > MPIDR_MAX_AFFLVL)
+	if (target_afflvl > get_max_afflvl())
 		return PSCI_E_INVALID_PARAMS;
 
 	/* Determine the 'state type' in the 'power_state' parameter */
diff --git a/services/std_svc/psci/psci_setup.c b/services/std_svc/psci/psci_setup.c
index a5ae4ef..8e9d15d 100644
--- a/services/std_svc/psci/psci_setup.c
+++ b/services/std_svc/psci/psci_setup.c
@@ -77,12 +77,18 @@
 		return PSCI_E_INVALID_PARAMS;
 
 	/*
+	 * Make sure we are within array limits.
+	 */
+	assert(min_idx >= 0 && max_idx < PSCI_NUM_AFFS);
+
+	/*
 	 * Bisect the array around 'mid' and then recurse into the array chunk
 	 * where the key is likely to be found. The mpidrs in each node in the
 	 * 'psci_aff_map' for a given affinity level are stored in an ascending
 	 * order which makes the binary search possible.
 	 */
 	mid = min_idx + ((max_idx - min_idx) >> 1);	/* Divide by 2 */
+
 	if (psci_aff_map[mid].mpidr > key)
 		return psci_aff_map_get_idx(key, min_idx, mid - 1);
 	else if (psci_aff_map[mid].mpidr < key)
@@ -95,6 +101,9 @@
 {
 	int rc;
 
+	if (aff_lvl > get_max_afflvl())
+		return NULL;
+
 	/* Right shift the mpidr to the required affinity level */
 	mpidr = mpidr_mask_lower_afflvls(mpidr, aff_lvl);
 
diff --git a/tools/fip_create/fip_create.c b/tools/fip_create/fip_create.c
index d1802b7..c940c5b 100644
--- a/tools/fip_create/fip_create.c
+++ b/tools/fip_create/fip_create.c
@@ -543,7 +543,7 @@
 					if (status != 0) {
 						printf("Failed to process %s\n",
 						       options[option_index].name);
-						break;
+						return status;
 					} else {
 						/* Update package */
 						*do_pack = 1;