summaryrefslogtreecommitdiffstats
path: root/mm/memory.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@g5.osdl.org>2005-11-29 23:03:14 +0100
committerLinus Torvalds <torvalds@g5.osdl.org>2005-11-29 23:03:14 +0100
commitc9cfcddfd65735437a4cb8563d6b66a6da8a5ed6 (patch)
tree618cdf37baafe8b283bcc9923d9dde89d6428fb5 /mm/memory.c
parentMerge master.kernel.org:/pub/scm/linux/kernel/git/tglx/mtd-2.6 (diff)
downloadlinux-c9cfcddfd65735437a4cb8563d6b66a6da8a5ed6.tar.xz
linux-c9cfcddfd65735437a4cb8563d6b66a6da8a5ed6.zip
VM: add common helper function to create the page tables
This logic was duplicated four times, for no good reason. Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'mm/memory.c')
-rw-r--r--mm/memory.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/mm/memory.c b/mm/memory.c
index 990e7dc666f8..74f95ae0510b 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -1146,6 +1146,18 @@ int zeromap_page_range(struct vm_area_struct *vma,
return err;
}
+pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl)
+{
+ pgd_t * pgd = pgd_offset(mm, addr);
+ pud_t * pud = pud_alloc(mm, pgd, addr);
+ if (pud) {
+ pmd_t * pmd = pmd_alloc(mm, pgd, addr);
+ if (pmd)
+ return pte_alloc_map_lock(mm, pmd, addr, ptl);
+ }
+ return NULL;
+}
+
/*
* This is the old fallback for page remapping.
*
@@ -1156,10 +1168,7 @@ int zeromap_page_range(struct vm_area_struct *vma,
static int insert_page(struct mm_struct *mm, unsigned long addr, struct page *page, pgprot_t prot)
{
int retval;
- pgd_t * pgd;
- pud_t * pud;
- pmd_t * pmd;
- pte_t * pte;
+ pte_t *pte;
spinlock_t *ptl;
retval = -EINVAL;
@@ -1167,14 +1176,7 @@ static int insert_page(struct mm_struct *mm, unsigned long addr, struct page *pa
goto out;
retval = -ENOMEM;
flush_dcache_page(page);
- pgd = pgd_offset(mm, addr);
- pud = pud_alloc(mm, pgd, addr);
- if (!pud)
- goto out;
- pmd = pmd_alloc(mm, pud, addr);
- if (!pmd)
- goto out;
- pte = pte_alloc_map_lock(mm, pmd, addr, &ptl);
+ pte = get_locked_pte(mm, addr, &ptl);
if (!pte)
goto out;
retval = -EBUSY;