Skip to content

Commit a7c46c0

Browse files
Navidemtorvalds
authored andcommitted
mm/gup: fix memory leak in __gup_benchmark_ioctl
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(). [[email protected]: rework code flow, return -EINVAL rather than -1] Link: http://lkml.kernel.org/r/[email protected] Fixes: 714a3a1 ("mm/gup_benchmark.c: add additional pinning methods") Signed-off-by: Navid Emamdoost <[email protected]> Reviewed-by: Andrew Morton <[email protected]> Reviewed-by: Ira Weiny <[email protected]> Reviewed-by: John Hubbard <[email protected]> Cc: Keith Busch <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Cc: Dave Hansen <[email protected]> Cc: Dan Williams <[email protected]> Cc: David Hildenbrand <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 941f762 commit a7c46c0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

mm/gup_benchmark.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
2626
unsigned long i, nr_pages, addr, next;
2727
int nr;
2828
struct page **pages;
29+
int ret = 0;
2930

3031
if (gup->size > ULONG_MAX)
3132
return -EINVAL;
@@ -63,7 +64,9 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
6364
NULL);
6465
break;
6566
default:
66-
return -1;
67+
kvfree(pages);
68+
ret = -EINVAL;
69+
goto out;
6770
}
6871

6972
if (nr <= 0)
@@ -85,7 +88,8 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
8588
gup->put_delta_usec = ktime_us_delta(end_time, start_time);
8689

8790
kvfree(pages);
88-
return 0;
91+
out:
92+
return ret;
8993
}
9094

9195
static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd,

0 commit comments

Comments
 (0)