Skip to contentSkip to conversation

mm/mmap.c: logic of find_vma_intersection repeated in __do_munmap

PATCH Applied Gonzalo Matias Juarez Tello 2 participants 2 messages Apr 9, 2021 – May 10, 2021

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

PATCH 1/1 mm/mmap.c: logic of find_vma_intersection repeated in __do_munmap

Logic of find_vma_intersection() (which is an inline fc) is repeated in __do_munmap().
Besides, prev is assigned a value before checking vma->vm_start >= end which might end up on a return statement making that assignment useless.

Calling find_vma_intersection() checks that condition and returns NULL if no vma is found, hence only the !vma check is needed in __do_munmap().

---
 mm/mmap.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
mm/mmap.c +2 -7
index 3f287599a7a3..59ceaa474a00 100644
@@ -2822,16 +2822,11 @@ int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len,
 	 */
 	arch_unmap(mm, start, end);
 
-	/* Find the first overlapping VMA */
-	vma = find_vma(mm, start);
+	/* Find the first overlapping VMA where start < vma->vm_end */
+	vma = find_vma_intersection(mm, start, end);
 	if (!vma)
 		return 0;
 	prev = vma->vm_prev;
-	/* we have  start < vma->vm_end  */
-
-	/* if it doesn't overlap, we have nothing.. */
-	if (vma->vm_start >= end)
-		return 0;
 
 	/*
 	 * If we need to split any vma, do it now to save pain later.
Signature · 1 line
2.31.1
maintainer
#1 lore raw
Quoted 21 lines · On Fri, 9 Apr 2021 13:21:26 -0300 Gonzalo Matias Juarez Tello…

Logic of find_vma_intersection() (which is an inline fc) is repeated in __do_munmap().
Besides, prev is assigned a value before checking vma->vm_start >= end which might end up on a return statement making that assignment useless.

Calling find_vma_intersection() checks that condition and returns NULL if no vma is found, hence only the !vma check is needed in __do_munmap().

...

mm/mmap.c +2 -2
@@ -2822,16 +2822,11 @@ int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len,
 	 */
 	arch_unmap(mm, start, end);
 
-	/* Find the first overlapping VMA */
-	vma = find_vma(mm, start);
+	/* Find the first overlapping VMA where start < vma->vm_end */
+	vma = find_vma_intersection(mm, start, end);
 	if (!vma)

mm/mmap.c int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len, · line 2832

Quoted 10 lines
mm/mmap.c +0 -5
 		return 0;
 	prev = vma->vm_prev;
-	/* we have  start < vma->vm_end  */
-
-	/* if it doesn't overlap, we have nothing.. */
-	if (vma->vm_start >= end)
-		return 0;
 
 	/*
 	 * If we need to split any vma, do it now to save pain later.

Looks good to me, thanks.