changeset 475:dcb543907cbb

os_mem_fl.c: os_CreatePartitionPool(): fixed error check logic
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 27 Jun 2014 02:24:27 +0000
parents 6e6d4c1ec733
children 536c53d3356c
files gsm-fw/gpf/osl/os_mem_fl.c
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/gsm-fw/gpf/osl/os_mem_fl.c	Fri Jun 27 01:20:23 2014 +0000
+++ b/gsm-fw/gpf/osl/os_mem_fl.c	Fri Jun 27 02:24:27 2014 +0000
@@ -306,17 +306,13 @@
 
 	sts = NU_Obtain_Semaphore(&MemSemCB, NU_SUSPEND);
 	j = 0;
-	part_group = 0;
 	part_group_head = 0;
 	for (i = 0; i <= MaxPoolGroups; i++) {
-		if (!PartGrpTable[i].grp_head || !PartGrpTable[i].name[0]) {
-			part_group = i;
+		if (!PartGrpTable[i].grp_head || !PartGrpTable[i].name[0])
 			break;
-		}
 		if (!strncmp(GroupName, PartGrpTable[i].name,
 			     RESOURCE_NAMELEN - 1)) {
 			part_group_head = PartGrpTable[i].grp_head;
-			part_group = i;
 			opool = part_group_head;
 			j++;
 			while (opool->next) {
@@ -326,12 +322,20 @@
 			break;
 		}
 	}
-	if (part_group > MaxPoolGroups) {
+	/*
+	 * This error check logic has been modified from the original
+	 * faithful reconstruction by Space Falcon.  In the original code
+	 * if MaxPoolGroups had been reached and the for loop above
+	 * never broke, the code would proceed to overwrite pool #0
+	 * instead of catching the error.
+	 */
+	if (i > MaxPoolGroups) {
 release_sem_return_err:
 		if (sts == NU_SUCCESS)
 			NU_Release_Semaphore(&MemSemCB);
 		return(OS_ERROR);
 	}
+	part_group = i;
 	if (!part_group_head) {
 		strncpy(PartGrpTable[part_group].name, GroupName,
 			RESOURCE_NAMELEN);