i915: use the VMA iterator
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Tue, 6 Sep 2022 19:49:04 +0000 (19:49 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 27 Sep 2022 02:46:25 +0000 (19:46 -0700)
Replace the linked list in probe_range() with the VMA iterator.

Link: https://lkml.kernel.org/r/20220906194824.2110408-65-Liam.Howlett@oracle.com
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Tested-by: Yu Zhao <yuzhao@google.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: SeongJae Park <sj@kernel.org>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/gpu/drm/i915/gem/i915_gem_userptr.c

index 8423df021b7138a02f77897e1b9cc98af743e35d..d4398948f01623d7474593eb4fb8de2690136301 100644 (file)
@@ -426,12 +426,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;
@@ -439,16 +438,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;
 }
 
 /*