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=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 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 973F9C00454 for ; Fri, 13 Dec 2019 23:12:38 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4EBAA2073D for ; Fri, 13 Dec 2019 23:12:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4EBAA2073D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 9E26B8E0005; Fri, 13 Dec 2019 18:12:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 993018E0001; Fri, 13 Dec 2019 18:12:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A9428E0005; Fri, 13 Dec 2019 18:12:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0056.hostedemail.com [216.40.44.56]) by kanga.kvack.org (Postfix) with ESMTP id 758188E0001 for ; Fri, 13 Dec 2019 18:12:37 -0500 (EST) Received: from smtpin13.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 294088249980 for ; Fri, 13 Dec 2019 23:12:37 +0000 (UTC) X-FDA: 76261669554.13.fear65_6e1c85370c856 X-HE-Tag: fear65_6e1c85370c856 X-Filterd-Recvd-Size: 3029 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Dec 2019 23:12:36 +0000 (UTC) X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Dec 2019 15:12:35 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,311,1571727600"; d="scan'208";a="211583507" Received: from iweiny-desk2.sc.intel.com ([10.3.52.157]) by fmsmga008.fm.intel.com with ESMTP; 13 Dec 2019 15:12:34 -0800 Date: Fri, 13 Dec 2019 15:12:34 -0800 From: Ira Weiny To: Navid Emamdoost Cc: Andrew Morton , "Kirill A. Shutemov" , Keith Busch , linux-mm@kvack.org, linux-kernel@vger.kernel.org, emamd001@umn.edu, jhubbard@nvidia.com Subject: Re: [PATCH v2] mm/gup: Fix memory leak in __gup_benchmark_ioctl Message-ID: <20191213231234.GB8347@iweiny-DESK2.sc.intel.com> References: <9a692d27-4654-f1fc-d4c5-c6efba02c8a9@nvidia.com> <20191213223751.4089-1-navid.emamdoost@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191213223751.4089-1-navid.emamdoost@gmail.com> User-Agent: Mutt/1.11.1 (2018-12-01) 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, Dec 13, 2019 at 04:37:41PM -0600, 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() by goto done. > > Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods") > Signed-off-by: Navid Emamdoost Reviewed-by: Ira Weiny > --- > Changes in v2: > -- added goto and ret value instead of return -1. > --- > mm/gup_benchmark.c | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c > index b160638f647e..b773b2568544 100644 > --- a/mm/gup_benchmark.c > +++ b/mm/gup_benchmark.c > @@ -24,7 +24,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > { > ktime_t start_time, end_time; > unsigned long i, nr_pages, addr, next; > - int nr; > + int nr, ret = 0; > struct page **pages; > > if (gup->size > ULONG_MAX) > @@ -63,8 +63,8 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > NULL); > break; > default: > - kvfree(pages); > - return -1; > + ret = -EINVAL; > + goto done; > } > > if (nr <= 0) > @@ -85,8 +85,9 @@ static int __gup_benchmark_ioctl(unsigned int cmd, > end_time = ktime_get(); > gup->put_delta_usec = ktime_us_delta(end_time, start_time); > > +done: > kvfree(pages); > - return 0; > + return ret; > } > > static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd, > -- > 2.17.1 > >