Received: by 10.223.176.46 with SMTP id f43csp244497wra; Tue, 23 Jan 2018 20:08:59 -0800 (PST) X-Google-Smtp-Source: AH8x227aBmRMdkggshJGY3BXtyVt4FllDB/YJ1+3VE1350E/eo8A71HQHA12PrD4Ak9uyewobZsZ X-Received: by 2002:a17:902:74ca:: with SMTP id f10-v6mr7106437plt.386.1516766939377; Tue, 23 Jan 2018 20:08:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516766939; cv=none; d=google.com; s=arc-20160816; b=0GfqW5J/mshm+gUB53isiDy6RtZGM63VwwNAcG1m69odQ5JY++adFo8imOePqgIBLr Ls9k1w55d6aNF+iZA7lKg1nwcZOXhbsNyLhrKYybtgcZVfFS56CzXOLTaMVdgk9G7RxT Rhuy5Nw2nH4LwbJbD5pXK+6R8/gQyFJr8AG+S9vCAPUQoYSFyje6dY69JO8PNtGGlm7Z HO/p4iRicsvrWtBPOSw31VydDvjq/T3YKMYAcODEPILW8mDHEvWBo5ptn3Xjxl5IR5gP 5j9DdEvxJWmTSPeVkDLwxOeTJFnJbaw8zZuijceNElzOXMhBH9muBGSXaTKkV7v+o8aC 0mpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=80UApOgHSSBM2qrSYEPyWkTolW48wtAtCxhUnQdlhXM=; b=C/sLroscMuA1fgy7ZYBlQ1EULHtnwGXCrBsDbifNc30+fwkqQxnxSGulRSJtR1Vyj4 k5Z7B76c8Zfu1WAwbGeZjDNjRTUuEZz1TUG1R7YPapHvhw+c/tTb+PKQFGhLFTPRuvIq JE8OakDUamzaRL4SFAPtD2Sa/dkiMLidSFH6AZ5dUKwl5hyjbaH67cbfpo7meGyR+1cj FEBHK8awKG5z2c9BHOt32s+CCECqVL2+QRKEtnKYkik/0TcfpWzETeLxWrkiRrcHqepj 9xnQ7mfkD7FefQ3dFgEFHTlzaS3yXe1/TkIDD7BzLsfMKHMTH2qpTvOaoXfzKY1VbwU8 7jTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kudzu-us.20150623.gappssmtp.com header.s=20150623 header.b=rJVmd4p2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c23-v6si5475167plo.664.2018.01.23.20.08.02; Tue, 23 Jan 2018 20:08:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kudzu-us.20150623.gappssmtp.com header.s=20150623 header.b=rJVmd4p2; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752435AbeAXEGw (ORCPT + 99 others); Tue, 23 Jan 2018 23:06:52 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:37984 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752274AbeAXEGu (ORCPT ); Tue, 23 Jan 2018 23:06:50 -0500 Received: by mail-qt0-f195.google.com with SMTP id z10so7193256qti.5 for ; Tue, 23 Jan 2018 20:06:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kudzu-us.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=80UApOgHSSBM2qrSYEPyWkTolW48wtAtCxhUnQdlhXM=; b=rJVmd4p2Y+IIr5scw0hnDueRbkZQW20v7TZYudkp7+Jub5CPiec0W7vf7n7HkMdvAp akO9qFPOI9K9UmYuVqzMB8Np3N3zzCqPYmZ2vqCz/wKvh9qYqmJK72VrR8ZEmi3jQDrn Ys+JDE7MmXvN1hgmHbY/Fwqaf1WunFHv69g0aY+vOhZ3BTXq6PGSXBt4S1TbMPU3ahT8 dpRTtCdiQWkWc05u8pw261RVu3npFXHd+hHrhv9VjDLuH/KEwgI26LYu8C29T3C3Hxjf vbhEpMYXSLLyNk6TVAmLdLfARisud3jZ9vosV3Eq/pQdkmiRr64X8SM/XGXcLFxpJz2b /IWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=80UApOgHSSBM2qrSYEPyWkTolW48wtAtCxhUnQdlhXM=; b=rbQfAQonW6LARFaywXlUMIa0shUixkzva9r5mmyBzViPI/poRPv28MaMrNnfxc2Swb Wv6Nt7XN838w0cJ6gv4IjkO3kra+HvJ5SQZmQlW0QrqizclUpwybSXhBeceUh4EoAkF9 /vk/jSUiwsXy1vXS7/WVqgbkN4EaXcw01sAuqdmtwkUUrF/OsX2Hjs/GRJLP2EmaBamM yCmWaqcRqeeQWHB5YTpAYrxJxCE6Qe9pG1bvOEXsoEDxM0/kFNELkfmF27SXiHIyku+k +5OCGQYywCD4kEL5QMb9WMLeaMnw0SwonEC4qXl67VgO4fZZ/LiXDijR83j1AmoVrXJk urRQ== X-Gm-Message-State: AKwxytedmqLMm+OB6wjumEUagP4p6814tWJRaLgHD7psvxWi24x57+hK Q4EbaJzKyuKsonMCFSkHcRd9BQ== X-Received: by 10.55.20.225 with SMTP id 94mr7182209qku.48.1516766809731; Tue, 23 Jan 2018 20:06:49 -0800 (PST) Received: from kudzu.us ([98.122.141.161]) by smtp.gmail.com with ESMTPSA id l188sm12711300qkd.36.2018.01.23.20.06.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jan 2018 20:06:49 -0800 (PST) Date: Tue, 23 Jan 2018 23:06:47 -0500 From: Jon Mason To: Serge Semin Cc: Colin King , Dave Jiang , Allen Hubbe , linux-ntb@googlegroups.com, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH][next] NTB: ntb_tool: fix memory leak on 'buf' on error exit path Message-ID: <20180124040646.GA20474@kudzu.us> References: <20180122093857.2174-1-colin.king@canonical.com> <20180122100239.GA32024@mobilestation> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180122100239.GA32024@mobilestation> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jan 22, 2018 at 01:02:39PM +0300, Serge Semin wrote: > On Mon, Jan 22, 2018 at 09:38:57AM +0000, Colin King wrote: > > From: Colin Ian King > > > > Currently there is a memory leak on buf when the call to ntb_mw_get_align > > fails. Add an exit err label and jump to this so that kfree on buf frees > > the memory. > > > > Detected by CoverityScan, CID#1464286 ("Resource leak") > > > > Fixes: d637628ce00c ("NTB: ntb_tool: Add full multi-port NTB API support") > > Signed-off-by: Colin Ian King > > Good catch, thanks! > > Acked-by: Serge Semin Applied to ntb-next Thanks, Jon > > > --- > > drivers/ntb/test/ntb_tool.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/ntb/test/ntb_tool.c b/drivers/ntb/test/ntb_tool.c > > index 920fc9b161b0..d592c0ffbd19 100644 > > --- a/drivers/ntb/test/ntb_tool.c > > +++ b/drivers/ntb/test/ntb_tool.c > > @@ -659,7 +659,7 @@ static ssize_t tool_mw_trans_read(struct file *filep, char __user *ubuf, > > ret = ntb_mw_get_align(inmw->tc->ntb, inmw->pidx, inmw->widx, > > &addr_align, &size_align, &size_max); > > if (ret) > > - return ret; > > + goto err; > > > > off += scnprintf(buf + off, buf_size - off, > > "Inbound MW \t%d\n", > > @@ -694,6 +694,8 @@ static ssize_t tool_mw_trans_read(struct file *filep, char __user *ubuf, > > &size_max); > > > > ret = simple_read_from_buffer(ubuf, size, offp, buf, off); > > + > > +err: > > kfree(buf); > > > > return ret; > > -- > > 2.15.1 > >