public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yuanhan Liu <yliu.null@gmail.com>
To: x86@kernel.org
Cc: linux-kernel@vger.kernel.org, Yuanhan Liu <yliu.null@gmail.com>,
	Jeremy Fitzhardinge <jeremy@goop.org>,
	Thomas Gleixner <tglx@linutronix.de>, Ingo Molnar <mingo@elte.hu>,
	"H. Peter Anvin" <hpa@zytor.com>
Subject: [PATCH] x86/mm: stop allocating pmd page if failed
Date: Tue, 24 Jul 2012 21:15:51 +0800	[thread overview]
Message-ID: <1343135751-8336-1-git-send-email-yliu.null@gmail.com> (raw)

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

Signed-off-by: Yuanhan Liu <yliu.null@gmail.com>
Cc: Jeremy Fitzhardinge <jeremy@goop.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: "H. Peter Anvin" <hpa@zytor.com>
---
 arch/x86/mm/pgtable.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
index 8573b83..6760348 100644
--- a/arch/x86/mm/pgtable.c
+++ b/arch/x86/mm/pgtable.c
@@ -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;
 	}
-- 
1.7.4.4


             reply	other threads:[~2012-07-24 13:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-24 13:15 Yuanhan Liu [this message]
2012-07-26  5:39 ` [PATCH] x86/mm: stop allocating pmd page if failed Jeremy Fitzhardinge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1343135751-8336-1-git-send-email-yliu.null@gmail.com \
    --to=yliu.null@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jeremy@goop.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox