]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - mm/gup_benchmark.c
mm/page-writeback.c: avoid potential division by zero in wb_min_max_ratio()
[mirror_ubuntu-bionic-kernel.git] / mm / gup_benchmark.c
index 5c8e2abeaa1598afbe0462762db25d2a017d814a..33be0b5762d34a6320108cf703c0ed6568d444d7 100644 (file)
@@ -19,11 +19,15 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
                struct gup_benchmark *gup)
 {
        ktime_t start_time, end_time;
-       unsigned long i, nr, nr_pages, addr, next;
+       unsigned long i, nr_pages, addr, next;
+       int nr;
        struct page **pages;
 
+       if (gup->size > ULONG_MAX)
+               return -EINVAL;
+
        nr_pages = gup->size / PAGE_SIZE;
-       pages = kvmalloc(sizeof(void *) * nr_pages, GFP_KERNEL);
+       pages = kvzalloc(sizeof(void *) * nr_pages, GFP_KERNEL);
        if (!pages)
                return -ENOMEM;
 
@@ -41,6 +45,8 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
                }
 
                nr = get_user_pages_fast(addr, nr, gup->flags & 1, pages + i);
+               if (nr <= 0)
+                       break;
                i += nr;
        }
        end_time = ktime_get();