]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - mm/gup.c
Merge tag 'led-fixes-for-5.2-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux.git] / mm / gup.c
index 2c08248d4fa279bece3a748d22a30a250d5e8bbe..ddde097cf9e4106bc02ea55538926f44ed8e587c 100644 (file)
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/err.h>
@@ -1041,10 +1042,6 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
                        BUG_ON(ret >= nr_pages);
                }
 
-               if (!pages)
-                       /* If it's a prefault don't insist harder */
-                       return ret;
-
                if (ret > 0) {
                        nr_pages -= ret;
                        pages_done += ret;
@@ -1060,8 +1057,12 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
                                pages_done = ret;
                        break;
                }
-               /* VM_FAULT_RETRY triggered, so seek to the faulting offset */
-               pages += ret;
+               /*
+                * VM_FAULT_RETRY triggered, so seek to the faulting offset.
+                * For the prefault case (!pages) we only update counts.
+                */
+               if (likely(pages))
+                       pages += ret;
                start += ret << PAGE_SHIFT;
 
                /*
@@ -1084,7 +1085,8 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
                pages_done++;
                if (!nr_pages)
                        break;
-               pages++;
+               if (likely(pages))
+                       pages++;
                start += PAGE_SIZE;
        }
        if (lock_dropped && *locked) {