Merge "msm: ocmem: Fix an issue with turning off the memory"
diff --git a/arch/arm/mach-msm/ocmem_sched.c b/arch/arm/mach-msm/ocmem_sched.c
index 2cff74b..8f9bab5 100644
--- a/arch/arm/mach-msm/ocmem_sched.c
+++ b/arch/arm/mach-msm/ocmem_sched.c
@@ -1432,17 +1432,14 @@
 	sched_dequeue(req);
 	mutex_unlock(&sched_mutex);
 
-	if (!TEST_STATE(req, R_FREE)) {
-
+	if (TEST_STATE(req, R_MAPPED)) {
+		/* unmap the interval and clear the memory */
 		rc = process_unmap(req, req->req_start, req->req_end);
 		if (rc < 0)
 			return -EINVAL;
-
-		rc = do_free(req);
-		if (rc < 0)
-			return -EINVAL;
 	}
 
+	/* Turn off the memory */
 	if (req->req_sz != 0) {
 
 		offset = phys_to_offset(req->req_start);
@@ -1456,6 +1453,13 @@
 
 	}
 
+	if (!TEST_STATE(req, R_FREE)) {
+		/* free the allocation */
+		rc = do_free(req);
+		if (rc < 0)
+			return -EINVAL;
+	}
+
 	inc_ocmem_stat(zone_of(req), NR_FREES);
 
 	ocmem_destroy_req(req);