mm/gup: fix memory leak in __gup_benchmark_ioctl
commit5.4-rM2-2.2.x-imx-squasheda7c46c0c0e
upstream. In the implementation of __gup_benchmark_ioctl() the allocated pages should be released before returning in case of an invalid cmd. Release pages via kvfree(). [akpm@linux-foundation.org: rework code flow, return -EINVAL rather than -1] Link: http://lkml.kernel.org/r/20191211174653.4102-1-navid.emamdoost@gmail.com Fixes:714a3a1eba
("mm/gup_benchmark.c: add additional pinning methods") Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: John Hubbard <jhubbard@nvidia.com> Cc: Keith Busch <keith.busch@intel.com> Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Dan Williams <dan.j.williams@intel.com> Cc: David Hildenbrand <david@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
parent
d1b69aabcd
commit
20170bfa3d
|
@ -26,6 +26,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
|
||||||
unsigned long i, nr_pages, addr, next;
|
unsigned long i, nr_pages, addr, next;
|
||||||
int nr;
|
int nr;
|
||||||
struct page **pages;
|
struct page **pages;
|
||||||
|
int ret = 0;
|
||||||
|
|
||||||
if (gup->size > ULONG_MAX)
|
if (gup->size > ULONG_MAX)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -63,7 +64,9 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
|
||||||
NULL);
|
NULL);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return -1;
|
kvfree(pages);
|
||||||
|
ret = -EINVAL;
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nr <= 0)
|
if (nr <= 0)
|
||||||
|
@ -85,7 +88,8 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
|
||||||
gup->put_delta_usec = ktime_us_delta(end_time, start_time);
|
gup->put_delta_usec = ktime_us_delta(end_time, start_time);
|
||||||
|
|
||||||
kvfree(pages);
|
kvfree(pages);
|
||||||
return 0;
|
out:
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd,
|
static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd,
|
||||||
|
|
Loading…
Reference in New Issue