From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A10EC2D0CA for ; Fri, 13 Dec 2019 22:23:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3B951214D8 for ; Fri, 13 Dec 2019 22:23:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="i4KM7W9N" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B951214D8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9E1318E0005; Fri, 13 Dec 2019 17:23:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9693C8E0001; Fri, 13 Dec 2019 17:23:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8587D8E0005; Fri, 13 Dec 2019 17:23:35 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0025.hostedemail.com [216.40.44.25]) by kanga.kvack.org (Postfix) with ESMTP id 6B7088E0001 for ; Fri, 13 Dec 2019 17:23:35 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 25113180AD807 for ; Fri, 13 Dec 2019 22:23:35 +0000 (UTC) X-FDA: 76261545990.27.coil01_7690ef8b5f442 X-HE-Tag: coil01_7690ef8b5f442 X-Filterd-Recvd-Size: 3620 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf29.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Dec 2019 22:23:34 +0000 (UTC) Received: from localhost.localdomain (c-73-231-172-41.hsd1.ca.comcast.net [73.231.172.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7C55E20706; Fri, 13 Dec 2019 22:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576275813; bh=4iChmOKy+iWyzBUqX73EkorUxBHm0c/M19HO10x0in0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=i4KM7W9Nv9QULJGh6tsFLMg6kACWSO3TPSt+iFvi0Lmz60OcH9UvQYZkapZjopQ6L bOgaiNRrN7wdN5Mmbr2wp6ipHtOVbzipeY8UqU1PrQLF0EPQmZFQ4R45mFjBf38I8E uhU1UDTTCEr1/BijD37EO8cG4BCMHJkEZpIVroA0= Date: Fri, 13 Dec 2019 14:23:32 -0800 From: Andrew Morton To: John Hubbard Cc: Navid Emamdoost , "Kirill A. Shutemov" , Keith Busch , , , Subject: Re: [PATCH] mm/gup: Fix memory leak in __gup_benchmark_ioctl Message-Id: <20191213142332.d7fafc243291eac302375c32@linux-foundation.org> In-Reply-To: <9a692d27-4654-f1fc-d4c5-c6efba02c8a9@nvidia.com> References: <20191211174653.4102-1-navid.emamdoost@gmail.com> <9a692d27-4654-f1fc-d4c5-c6efba02c8a9@nvidia.com> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Fri, 13 Dec 2019 13:40:15 -0800 John Hubbard wrote: > On 12/11/19 9:46 AM, Navid Emamdoost wrote: > > 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(). > > > > Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods") > > Signed-off-by: Navid Emamdoost > > --- > > mm/gup_benchmark.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c > > index 7dd602d7f8db..b160638f647e 100644 > > --- a/mm/gup_benchmark.c > > +++ b/mm/gup_benchmark.c > > @@ -63,6 +63,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > > NULL); > > break; > > default: > > + kvfree(pages); > > return -1; > > } > > > > Hi, > > The patch is correct, but I would like to second Ira's request for a ret value, > and a "goto done" to use a single place to kvfree, if you don't mind. > Fair enough. And let's make it return -EINVAL rather than -1, which appears to be -EPERM. --- a/mm/gup_benchmark.c~mm-gup-fix-memory-leak-in-__gup_benchmark_ioctl-fix +++ a/mm/gup_benchmark.c @@ -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; @@ -64,7 +65,8 @@ static int __gup_benchmark_ioctl(unsigne break; default: kvfree(pages); - return -1; + ret = -EINVAL; + goto out; } if (nr <= 0) @@ -86,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, _