Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2674982ybl; Thu, 29 Aug 2019 11:18:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGhVH7+QXENwztAkq90hNvgcQESyxUOh+ql2f+F6dM2f/2rlEfBxIOqaDySrP/hfy5Oa3z X-Received: by 2002:a17:90a:cb88:: with SMTP id a8mr11096947pju.111.1567102701824; Thu, 29 Aug 2019 11:18:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567102701; cv=none; d=google.com; s=arc-20160816; b=fIkkkYWzd4NNLk4kIANG8wM3Eqkyb299RDeZChu29aRhYg2mxZukwK4hRPchhENF4T QJSW1BJrAMCeWdxmZjAGfmdnqUrgKrmZjdXd57ss20KBOCojDnaJxh5mDTvXaK+rKHVJ zVlsl4rdZU8qWPs7AU9d5FGIb5J9NpG+eoonzX3tyoRLkiizkFdHTZn3DJXngep3x3Mr 9X3701CVvT2JOA6zRTWYGQzntqUtzHx9OZx1KPdZY82fWjzwm8u8lk0cuCYm9bNuiyNF 0V6BE8H+hblbUCj8vO3FeA6atPZS4zR2hZqDuV4Ne1tF0BDJrJt0s7rgG4ciFIm5INFb uITg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ga6x1E4Wr6BXSHHdQA2fY63jEw7Fjal3VSo/BYHWkLk=; b=kiyQhSHafNC/GT2NgTG5OchuEm/dzdpW76K8wAQgwQTpJWyiu4dtfh+7TnYGAURlMp wVROds6mKwAI96dhsyd8yol7wHx+5vsC1TdfxuMM/ZrE0Jx8XHdVf5LcgIS0BuH3Owkt GGgarzqq7TDupQzren8uQ8EDVl/EgPa0q0vW2FW3GLIP83meJpqxnwIqfqt5VWB158Qo pjeGSClO4LAkPzOHYbAuBKIQk9ALixdJd1xqg/oWXnSDGbXMXaVuy73oq3oQR2yrY579 3sFt3usnb0FeTlTjLB8+b9m7JXjA+GFfnDgldadidWYCubv+ZYDCQzphjW943X76xltx h7dA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=cyWUx2go; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t1si2717872pjv.5.2019.08.29.11.18.05; Thu, 29 Aug 2019 11:18:21 -0700 (PDT) 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=@kernel.org header.s=default header.b=cyWUx2go; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729261AbfH2SPT (ORCPT + 99 others); Thu, 29 Aug 2019 14:15:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:56926 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729216AbfH2SPO (ORCPT ); Thu, 29 Aug 2019 14:15:14 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 921DA23426; Thu, 29 Aug 2019 18:15:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102513; bh=nXmAoySra2wHVmQxvsxSHEs4TACze4t9dD+qq2bM55I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cyWUx2goZDQRTnxjQ1HMeuiDO5fpABNJ/1io7H9vqH5KcoKcupvBBh1yWYIfI6cPc TqcJW2GDTDvxZSTTRvbQBYyKvONvee2HJq87IO8oGTgKFefmfEBCO7IRmH6Ai3Gt5t RqOjT2TfnyEsUcNeTxhudyR8xb2WyCoaedn+Wlyc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Wenwen Wang , Leon Romanovsky , Dennis Dalessandro , Doug Ledford , Sasha Levin , linux-rdma@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 61/76] infiniband: hfi1: fix a memory leak bug Date: Thu, 29 Aug 2019 14:12:56 -0400 Message-Id: <20190829181311.7562-61-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829181311.7562-1-sashal@kernel.org> References: <20190829181311.7562-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Wenwen Wang [ Upstream commit b08afa064c320e5d85cdc27228426b696c4c8dae ] In fault_opcodes_read(), 'data' is not deallocated if debugfs_file_get() fails, leading to a memory leak. To fix this bug, introduce the 'free_data' label to free 'data' before returning the error. Signed-off-by: Wenwen Wang Reviewed-by: Leon Romanovsky Acked-by: Dennis Dalessandro Link: https://lore.kernel.org/r/1566156571-4335-1-git-send-email-wenwen@cs.uga.edu Signed-off-by: Doug Ledford Signed-off-by: Sasha Levin --- drivers/infiniband/hw/hfi1/fault.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/infiniband/hw/hfi1/fault.c b/drivers/infiniband/hw/hfi1/fault.c index 93613e5def9b7..814324d172950 100644 --- a/drivers/infiniband/hw/hfi1/fault.c +++ b/drivers/infiniband/hw/hfi1/fault.c @@ -214,7 +214,7 @@ static ssize_t fault_opcodes_read(struct file *file, char __user *buf, return -ENOMEM; ret = debugfs_file_get(file->f_path.dentry); if (unlikely(ret)) - return ret; + goto free_data; bit = find_first_bit(fault->opcodes, bitsize); while (bit < bitsize) { zero = find_next_zero_bit(fault->opcodes, bitsize, bit); @@ -232,6 +232,7 @@ static ssize_t fault_opcodes_read(struct file *file, char __user *buf, data[size - 1] = '\n'; data[size] = '\0'; ret = simple_read_from_buffer(buf, len, pos, data, size); +free_data: kfree(data); return ret; } -- 2.20.1