]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
convert vma_expand() to prealloc
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 21 Apr 2022 22:00:09 +0000 (18:00 -0400)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Thu, 21 Apr 2022 22:35:00 +0000 (18:35 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
mm/mmap.c

index 2aa27adb39b1ad96d78a40b50dd7c9f2ed309386..4ef7d19e9ca891b4556fcb64262f5f0f99385066 100644 (file)
--- a/mm/mmap.c
+++ b/mm/mmap.c
@@ -559,6 +559,7 @@ inline int vma_expand(struct ma_state *mas, struct vm_area_struct *vma,
        struct anon_vma *anon_vma = vma->anon_vma;
        struct file *file = vma->vm_file;
        bool remove_next = false;
+       bool anon_cloned = false;
 
        if (next && (vma != next) && (end == next->vm_end)) {
                remove_next = true;
@@ -569,6 +570,7 @@ inline int vma_expand(struct ma_state *mas, struct vm_area_struct *vma,
                        error = anon_vma_clone(vma, next);
                        if (error)
                                return error;
+                       anon_cloned = true;
                }
        }
 
@@ -577,6 +579,9 @@ inline int vma_expand(struct ma_state *mas, struct vm_area_struct *vma,
        /* Only handles expanding */
        VM_BUG_ON(vma->vm_start < start || vma->vm_end > end);
 
+       if (mas_preallocate(mas, vma, GFP_KERNEL))
+               goto nomem;
+
        vma_adjust_trans_huge(vma, start, end, 0);
 
        if (file) {
@@ -631,6 +636,11 @@ inline int vma_expand(struct ma_state *mas, struct vm_area_struct *vma,
 
        validate_mm(mm);
        return 0;
+
+nomem:
+       if (anon_cloned)
+               unlink_anon_vmas(vma);
+       return -ENOMEM;
 }
 
 /*