Received: by 10.223.176.46 with SMTP id f43csp2691216wra; Mon, 22 Jan 2018 01:41:10 -0800 (PST) X-Google-Smtp-Source: AH8x226FiddwCFDpPWGSYZ5POSN/zbBIYDzd/SXokIhdGX1JBJU6abs74SC5GItFe92aBmPGfi22 X-Received: by 2002:a17:902:ba92:: with SMTP id k18-v6mr3088677pls.146.1516614070867; Mon, 22 Jan 2018 01:41:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516614070; cv=none; d=google.com; s=arc-20160816; b=ZyAzurRhxMZzi5+sEKz4MuAyA0dQwi+mvZh0YBBm2zyhx6yjxAjE64qhfTUjlUAkMs ui7PsbmX8Fq046Pgyp9mEXyxNIlblvrJTb0uxlMxPspHSME3KLB/qQLij6TiFOkovcvE AeSUpqFuOT+SadLAzZLTvJxjUVf/Hlf6n3EX74JgF3BuX72guZaC2aKuacDodko9riZu 9Moj5HT4mXo/Vyn93ex0LvHyoRVaufdgGgeV4vJ+aN+XtvB3gyD97GhuhHCLIV/PPwDd V6pF4DeyP75Cjnwc34fnPtOak58TwJ34L6i6mCS44p4uNmw57eq75NhLwJQIDoImibXs Ge2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:arc-authentication-results; bh=+96V911XP9iaFMtLFokttqJcM+5ITo6sFzaf4Nj6O5k=; b=o/6PWoVR8U5/LZysX7dWlrraeGOMmE2MTL7UuO5KU73DR+Jmq8DfueQyKfMhfGfjaF BE/zAIn6C5mlaQQVvnXKqYlFRzj/BeeJEZ6+gAq0Bp48qsThh3L3YCQqK3deVvdUbaKT PITT0IH7qo3YT56M8+B3ZRmrnP89gpSPx4dYal28HGGRlJ4XeYIIML31SGo+L/kipNHn +7qfnfXii2n/dtynv9rn6MRaTE8RcybPLpCqUXp+cvqxfBKUbk78WkqCyETXP7GrkiND Kh+rGn2BqCut15fiMAuGXpTfaRbajOC2EaAhXU0n+SAV/jy7bAUfiQOvB6OnjAp94ANs dSjw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bd5-v6si3230736plb.431.2018.01.22.01.40.56; Mon, 22 Jan 2018 01:41: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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751869AbeAVJjD (ORCPT + 99 others); Mon, 22 Jan 2018 04:39:03 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:60008 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751622AbeAVJjB (ORCPT ); Mon, 22 Jan 2018 04:39:01 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.76) (envelope-from ) id 1edYZ8-0001qh-8z; Mon, 22 Jan 2018 09:38:58 +0000 From: Colin King To: Jon Mason , Dave Jiang , Allen Hubbe , Serge Semin , linux-ntb@googlegroups.com Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] NTB: ntb_tool: fix memory leak on 'buf' on error exit path Date: Mon, 22 Jan 2018 09:38:57 +0000 Message-Id: <20180122093857.2174-1-colin.king@canonical.com> X-Mailer: git-send-email 2.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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