Skip to contentSkip to conversation

mm/gup: fix memory leak in __gup_benchmark_ioctl

PATCH New [email protected] 1 participant 1 message Jan 4, 2020 Memory management

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 13/17 mm/gup: fix memory leak in __gup_benchmark_ioctl

From: Navid Emamdoost <[email protected]>
Subject: 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]
Fixes 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods")
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]>

---

 mm/gup_benchmark.c |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
mm/gup_benchmark.c renamed from mm/gup_benchmark.c~mm-gup-fix-memory-leak-in-__gup_benchmark_ioctl +6 -2
@@ -26,6 +26,7 @@ static int __gup_benchmark_ioctl(unsigne
 	unsigned long i, nr_pages, addr, next;
 	int nr;
 	struct page **pages;
+	int ret = 0;
 
 	if (gup->size > ULONG_MAX)
 		return -EINVAL;
@@ -63,7 +64,9 @@ static int __gup_benchmark_ioctl(unsigne
 					    NULL);
 			break;
 		default:
-			return -1;
+			kvfree(pages);
+			ret = -EINVAL;
+			goto out;
 		}
 
 		if (nr <= 0)
@@ -85,7 +88,8 @@ static int __gup_benchmark_ioctl(unsigne
 	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,

_