Received: by 10.223.176.46 with SMTP id f43csp2709581wra; Mon, 22 Jan 2018 02:03:11 -0800 (PST) X-Google-Smtp-Source: AH8x227wwoo312xLO+5kTvwOCmZH0g0Ivml8BtrE0SpKX97YAFU6Zxas6ktIDVBavHa5ZgPDrhWo X-Received: by 10.99.144.76 with SMTP id a73mr6813770pge.376.1516615391027; Mon, 22 Jan 2018 02:03:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516615390; cv=none; d=google.com; s=arc-20160816; b=eks9fWVt+y/E7VnGpEmbOnOoRogjk6CksJVm4gNvOvzkILTc4RqaPSYmLjP6N+PM36 ft79JYLmALP0Aj/hN5hbUmfKWKf/GaFjXjTy4C4JckZ1UykmHwicluIC2tJFuZuwi4uk xgOOIU/UTXyMyV1/MevaQaTRq+gkWosZe/V92XHm60voldlQllSjYKdA380HbBPxJesv kfUJ7xyAgNHdelK4XeaqgzjRN+GrjwHR/GVXa1QjmSUPHeetwsHslJGDn24ZE1+zntHN bz1GDiRamXmJITOn3iIvIUAbcB9hoSVcDJ0dcZLy2xRakXKsa5t/5MlpLDYdny7YXiOw L+Kw== 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=k9q9pHlR6bbEjT053Eg9zxlQ/8Ncnkhs6uXB+JDdZIg=; b=OjdlPWnSoxWE+X4NCGBys9odO6tn84PrWLpDFMkxwq+BAjDSpzCoku6y8Pd9lcxXj+ 2+tH6ytKsZY0M5yh1ImLUqkrL9fWdAqLaZfhiJcDPdMZ50sCmZh20cchtvKZQvzSuRWI 1HoTBuN3k3IcNmvIfoKKrADNg7mGjTfvuWtROliXeqtimL3g2wQJh6tlxs7jnW0FOjYn y9iMaBoklGwvArVmotLFKhz0uRZDH17/P702075Z4G4R04cc5dTXoBg/P8kzUaTv679V xoq/7oEhk67daC/2D4gyJ57DwLZaIM0Gz17lj2qxX9+zr4OTBYgOzhVsOjU/ag0sHdqU byPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Q1tI+LcQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f13si15190173pfj.28.2018.01.22.02.02.56; Mon, 22 Jan 2018 02:03:10 -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=@gmail.com header.s=20161025 header.b=Q1tI+LcQ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751107AbeAVKCb (ORCPT + 99 others); Mon, 22 Jan 2018 05:02:31 -0500 Received: from mail-lf0-f66.google.com ([209.85.215.66]:37573 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750890AbeAVKCa (ORCPT ); Mon, 22 Jan 2018 05:02:30 -0500 Received: by mail-lf0-f66.google.com with SMTP id f3so9844382lfe.4; Mon, 22 Jan 2018 02:02:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=k9q9pHlR6bbEjT053Eg9zxlQ/8Ncnkhs6uXB+JDdZIg=; b=Q1tI+LcQH3toMBuSv+KzMSw86emUUUUu+wRphF/iAg+poVxs67U0xzsLVaYVbR55lV AexR3FeyRZfUn1am2pNaN4ag+e41ISCb4MBfgqTCvxNhQc1LBkD08910hh9ABprXHTax ZZtMP2Pubq8LZM3aFNwhJ4gY7ON496giLrmmd9VRvTrXyqqudaEcV4FTsgYpUBvfc4DG cjZlmVIm8PRfOHuUp+jRlcVe1V2VDW0rHQEzWq1OcMU1twTa0dtR8pIS2fmJgybVlNxJ AGrMXsK2Cf4iKySRzxkzqfRMVKcoK7YF8CB+XEUK135EGO0Mf2/tqeppDbH3wPjqQ2ud eSpQ== 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=k9q9pHlR6bbEjT053Eg9zxlQ/8Ncnkhs6uXB+JDdZIg=; b=Ain6ec6w5WPkrVHoO9u+E94NZ6+YtiQLWlVNj4YI7esDCVAOtf2PMmLmIQAw/H/XPc WMBmBag9jep1WnBq2nYYUzos7a0muwd2AUrAOi3wIyXbNkOJMNTxnbDDgA367+cCzRqa bxOluk8bCGpC+s2mapGFzdZZnvpfze5+Z4Kn7pIltFZl8hWPd4OoyzpDHJBKrVlwbFBs IpSwiZayXy4Wm1BvV6qZ1Hc6/aDMdaujvS6g1ycmTb+oCAuC2snBJk4hlXBkVtKq+cU2 rFZMZpE5syB/cL5p8zMijDOKG5iP5yTWzUc/EEsJBXHQvrCKvM4bki4WijFGpe1cJ5PC WBmw== X-Gm-Message-State: AKwxytdWfnOrKtss/Q7ABscg5IAuPG3aX1ceUDAk8ojedPUADLbuDBA1 eY3dI0DC3YIKK9dtPRATK2k= X-Received: by 10.46.82.23 with SMTP id g23mr3014598ljb.67.1516615348522; Mon, 22 Jan 2018 02:02:28 -0800 (PST) Received: from mobilestation ([95.79.164.146]) by smtp.gmail.com with ESMTPSA id 76sm2576082lfq.7.2018.01.22.02.02.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Jan 2018 02:02:27 -0800 (PST) Date: Mon, 22 Jan 2018 13:02:39 +0300 From: Serge Semin To: Colin King Cc: Jon Mason , 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: <20180122100239.GA32024@mobilestation> References: <20180122093857.2174-1-colin.king@canonical.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180122093857.2174-1-colin.king@canonical.com> User-Agent: Mutt/1.5.24 (2015-08-30) 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 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 > --- > 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 >