Skip to content

Commit

Permalink
mm/gup: fix memory leak in __gup_benchmark_ioctl
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Navidem authored and torvalds committed Jan 4, 2020
1 parent 941f762 commit a7c46c0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions mm/gup_benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
unsigned long i, nr_pages, addr, next;
int nr;
struct page **pages;
int ret = 0;

if (gup->size > ULONG_MAX)
return -EINVAL;
Expand Down Expand Up @@ -63,7 +64,9 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
NULL);
break;
default:
return -1;
kvfree(pages);
ret = -EINVAL;
goto out;
}

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

kvfree(pages);
return 0;
out:
return ret;
}

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

0 comments on commit a7c46c0

Please sign in to comment.