Skip to contentSkip to conversation

x86/mm: stop allocating pmd page if failed

PATCH In review Yuanhan Liu 2 participants 2 messages Jul 24, 2012 – Jul 26, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/mm: stop allocating pmd page if failed

The old code would call __get_free_page() even though previous allocation fail met. This is not needed.

Cc Jeremy Fitzhardinge <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/mm/pgtable.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
arch/x86/mm/pgtable.c +9 -9
index 8573b83..6760348 100644
@@ -181,24 +181,24 @@ static void free_pmds(pmd_t *pmds[])
 {
 	int i;
 
-	for(i = 0; i < PREALLOCATED_PMDS; i++)
-		if (pmds[i])
-			free_page((unsigned long)pmds[i]);
+	for(i = 0; i < PREALLOCATED_PMDS; i++) {
+		if (pmds[i] == NULL)
+			break;
+		free_page((unsigned long)pmds[i]);
+	}
 }
 
 static int preallocate_pmds(pmd_t *pmds[])
 {
 	int i;
-	bool failed = false;
 
 	for(i = 0; i < PREALLOCATED_PMDS; i++) {
-		pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
-		if (pmd == NULL)
-			failed = true;
-		pmds[i] = pmd;
+		pmds[i] = (pmd_t *)__get_free_page(PGALLOC_GFP);
+		if (pmds[i] == NULL)
+			break;
 	}
 
-	if (failed) {
+	if (i < PREALLOCATED_PMDS) {
 		free_pmds(pmds);
 		return -ENOMEM;
 	}
Signature · 1 line
1.7.4.4
#1 lore raw
Quoted 2 lines · Yuanhan Liu

The old code would call __get_free_page() even though previous allocation fail met. This is not needed.

Yeah, I guess, but its hardly worth changing.

J

Quoted 48 lines
Cc Jeremy Fitzhardinge <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc "H. Peter Anvin" <[email protected]>
---
 arch/x86/mm/pgtable.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
arch/x86/mm/pgtable.c +9 -9
index 8573b83..6760348 100644
@@ -181,24 +181,24 @@ static void free_pmds(pmd_t *pmds[])
 {
 	int i;
 
-	for(i = 0; i < PREALLOCATED_PMDS; i++)
-		if (pmds[i])
-			free_page((unsigned long)pmds[i]);
+	for(i = 0; i < PREALLOCATED_PMDS; i++) {
+		if (pmds[i] == NULL)
+			break;
+		free_page((unsigned long)pmds[i]);
+	}
 }
 
 static int preallocate_pmds(pmd_t *pmds[])
 {
 	int i;
-	bool failed = false;
 
 	for(i = 0; i < PREALLOCATED_PMDS; i++) {
-		pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
-		if (pmd == NULL)
-			failed = true;
-		pmds[i] = pmd;
+		pmds[i] = (pmd_t *)__get_free_page(PGALLOC_GFP);
+		if (pmds[i] == NULL)
+			break;
 	}
 
-	if (failed) {
+	if (i < PREALLOCATED_PMDS) {
 		free_pmds(pmds);
 		return -ENOMEM;
 	}