linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/gup: Fix memory leaks in __gup_benchmark_ioctl
@ 2019-11-22 22:41 Navid Emamdoost
  2019-11-25  9:25 ` David Hildenbrand
  0 siblings, 1 reply; 2+ messages in thread
From: Navid Emamdoost @ 2019-11-22 22:41 UTC (permalink / raw)
  To: Andrew Morton, linux-mm, linux-kernel; +Cc: emamd001, Navid Emamdoost

In the implementation of __gup_benchmark_ioctl() memory is leaked if the
passed cmd is invalid. Release pages before returning -1.

Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods")
Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
---
 mm/gup_benchmark.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c
index 7dd602d7f8db..33ede5727523 100644
--- a/mm/gup_benchmark.c
+++ b/mm/gup_benchmark.c
@@ -23,7 +23,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
 		struct gup_benchmark *gup)
 {
 	ktime_t start_time, end_time;
-	unsigned long i, nr_pages, addr, next;
+	unsigned long i, j, nr_pages, addr, next;
 	int nr;
 	struct page **pages;
 
@@ -63,6 +63,12 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
 					    NULL);
 			break;
 		default:
+			for (j = 0; j < i; j++) {
+				if (!pages[j])
+					break;
+				put_page(pages[j]);
+			}
+			kvfree(pages);
 			return -1;
 		}
 
-- 
2.17.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-25  9:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-22 22:41 [PATCH] mm/gup: Fix memory leaks in __gup_benchmark_ioctl Navid Emamdoost
2019-11-25  9:25 ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox