From: Liam R. Howlett Date: Thu, 23 Jul 2020 19:41:56 +0000 (-0400) Subject: mm/mmap: Add inline munmap_vma_range() for code readability X-Git-Tag: howlett/maple/20200727~9 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=588e68d4bb60fe2ddb4358edc82e90d9af191027;p=users%2Fjedix%2Flinux-maple.git mm/mmap: Add inline munmap_vma_range() for code readability Signed-off-by: Liam R. Howlett --- diff --git a/mm/mmap.c b/mm/mmap.c index 4f55bda990a3..7c442fd04c18 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -579,6 +579,32 @@ static inline struct vm_area_struct *next_vma_or_first(struct mm_struct *mm, return vma->vm_next; } + +/* Private + * munmap_vma_range() - Find all the vm_area_struct that overlap from @start to + * @end and munmap them. Set @pprev to the previous vm_area_struct. + * + * @mm: The mm struct + * @start: The start address. + * @len: The length of the range. + * @pprev: pointer to the pointer that will be set to previous vm_area_struct + * @rb_link - the rb_node + * @rb_parent - the parent rb_node + * + * Returns: -ENOMEM on munmap failure or 0 on success. + */ +static inline int +munmap_vma_range(struct mm_struct *mm, unsigned long start, unsigned long len, + struct vm_area_struct **pprev, struct rb_node ***rb_link, + struct rb_node **rb_parent, struct list_head *uf) +{ + + while (find_vma_links(mm, start, start + len, pprev, rb_link, rb_parent)) + if (do_munmap(mm, start, len, uf)) + return -ENOMEM; + + return 0; +} static unsigned long count_vma_pages_range(struct mm_struct *mm, unsigned long addr, unsigned long end) { @@ -1725,13 +1751,9 @@ unsigned long mmap_region(struct file *file, unsigned long addr, return -ENOMEM; } - /* Clear old maps */ - while (find_vma_links(mm, addr, addr + len, &prev, &rb_link, - &rb_parent)) { - if (do_munmap(mm, addr, len, uf)) - return -ENOMEM; - } - + /* Clear old maps, set up prev, rb_link, rb_parent, and uf */ + if (munmap_vma_range(mm, addr, len, &prev, &rb_link, &rb_parent, uf)) + return -ENOMEM; /* * Private writable mapping: check memory availability */ @@ -3025,14 +3047,9 @@ static int do_brk_flags(unsigned long addr, unsigned long len, unsigned long fla if (error) return error; - /* - * Clear old maps. this also does some error checking for us - */ - while (find_vma_links(mm, addr, addr + len, &prev, &rb_link, - &rb_parent)) { - if (do_munmap(mm, addr, len, uf)) - return -ENOMEM; - } + /* Clear old maps, set up prev, rb_link, rb_parent, and uf */ + if (munmap_vma_range(mm, addr, len, &prev, &rb_link, &rb_parent, uf)) + return -ENOMEM; /* Check against address space limits *after* clearing old maps... */ if (!may_expand_vm(mm, flags, len >> PAGE_SHIFT))