]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
i915: Use the VMA iterator
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Sat, 30 Oct 2021 03:46:58 +0000 (23:46 -0400)
committerMatthew Wilcox (Oracle) <willy@infradead.org>
Mon, 1 Nov 2021 14:43:50 +0000 (10:43 -0400)
Replace the O(n.log(n)) loop with an O(n) loop.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
drivers/gpu/drm/i915/gem/i915_gem_userptr.c

index 8ea0fa665e5305788a078765874d1488246996c4..9988a25fd8fe713a8e9b7c4cc0b5db5d520322f2 100644 (file)
@@ -422,12 +422,11 @@ static const struct drm_i915_gem_object_ops i915_gem_userptr_ops = {
 static int
 probe_range(struct mm_struct *mm, unsigned long addr, unsigned long len)
 {
-       const unsigned long end = addr + len;
+       VMA_ITERATOR(vmi, mm, addr);
        struct vm_area_struct *vma;
-       int ret = -EFAULT;
 
        mmap_read_lock(mm);
-       for (vma = find_vma(mm, addr); vma; vma = vma->vm_next) {
+       for_each_vma_range(vmi, vma, addr + len) {
                /* Check for holes, note that we also update the addr below */
                if (vma->vm_start > addr)
                        break;
@@ -435,16 +434,13 @@ probe_range(struct mm_struct *mm, unsigned long addr, unsigned long len)
                if (vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP))
                        break;
 
-               if (vma->vm_end >= end) {
-                       ret = 0;
-                       break;
-               }
-
                addr = vma->vm_end;
        }
        mmap_read_unlock(mm);
 
-       return ret;
+       if (vma)
+               return -EFAULT;
+       return 0;
 }
 
 /*