Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1873950ybl; Sun, 18 Aug 2019 12:30:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqxVO3+6zFcimJVW8YTB8NYhBJ3neibXFyfTOVZ35HNuua7n5Qd0TmH0IYTlElLl9A4Y0IVC X-Received: by 2002:a17:90a:b00a:: with SMTP id x10mr17888351pjq.113.1566156644269; Sun, 18 Aug 2019 12:30:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566156644; cv=none; d=google.com; s=arc-20160816; b=Bin3jKwTxtC4vEyEDKrhEju//tmakpTWktqQ4OTcEdMYhJtS1boymkFTyx+yM441UV PZr/vpFBTAspQnjIIEbRBx7fxOQVTBz4isRYD2tFxo2brYnJfTbkFhHSyHCFexvcm3b/ kb9l30LaVaetef1h/hzFocBnlXCYGD6+09DASXu5gzNLZxvxYmN+Yx5APv4D3khDqIyq iKpRMwrjalAOzyl8j1Fdpuah0AxsA6Q5MIwX0evI2NXOzxdRnTviPO65hOQVmZ8S7jNp TUPPCPC5l8/REFQQprJ0TwNw3TV7X5iIMjSN48Y4tcgx4PKBEc8KevWSQCw8XtJ8IWC7 7y4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=WwJ07zoBP7ifoIvwMolWLi9zDNgesbiXAJZqIP13xyU=; b=w77r2tv4meC2Dwi+oNXRJ/yYfcG9TFT50gD2I6z+4cBlWeOn4GLLGIWCAe/24LdhZ/ ROEWiIYTTVEHPa8muI5TEYnrMf3atwV3jnNsrx1346xwooEcFj3TI4zAJ2zh8oBQpa7N zulzuK+D4n8NWh9qJBU0nzhMqnxt4opHN0tP8KtsQQuaUfjDmtP40yDW/UZEucOohq07 MLzEtqq3YSKQlmVoqG2Ou3FZg8xEi30oMsWNug5L0feXnuJnN9T9KLCXWUTiBxW+Y/H4 7JRf8ddL8cKJw9fcVQ27gESqi9Ccpwvc48/AUPkRrgX4l1Dp4aLWgvdWpDu7rA+omj9t 0qaw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r13si8376788pgn.420.2019.08.18.12.30.29; Sun, 18 Aug 2019 12:30:44 -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; 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 S1726952AbfHRT3h (ORCPT + 99 others); Sun, 18 Aug 2019 15:29:37 -0400 Received: from mail-yw1-f67.google.com ([209.85.161.67]:40134 "EHLO mail-yw1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726005AbfHRT3h (ORCPT ); Sun, 18 Aug 2019 15:29:37 -0400 Received: by mail-yw1-f67.google.com with SMTP id z64so3462416ywe.7; Sun, 18 Aug 2019 12:29:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=WwJ07zoBP7ifoIvwMolWLi9zDNgesbiXAJZqIP13xyU=; b=f3OrpmCVjToQIiJVkJzZPIYoowm/mu20eWCPYW3rM/fsfKc6sys6dVlwFrac6helcD MoivDJhgZBdnqdvV5MpggRnaSmD7tgitBEwqfBS2sNzqkj8A4xs2b0OCPWJK2pAC9ouA A3ASy94U/LDkJMxbviR0yUUMXdSxkYR6kebJ7IBGWJiaJvePBzcewUzJHBUARjFgnTGX lmW0TRRmUoUAVKU/rCTUmZG9Y3dpk1iAhLEdVPs6071Fo3UFNdn9YYloeNc9qt0agzEN on0B2sXQHGl+nnXfsKKWps1kn3IYUAmWf55Nyz61NEpiJfg9/4lohsyzFns/3NPmD5GL 5m4g== X-Gm-Message-State: APjAAAUSni5d7EsO2PdXnXnOo/bDEATtz0FKMuhdJoK4OB1MlC+MYJwy hzAklA2hbPmI1/onzDlkaM8= X-Received: by 2002:a81:18d5:: with SMTP id 204mr13989252ywy.165.1566156576681; Sun, 18 Aug 2019 12:29:36 -0700 (PDT) Received: from localhost.localdomain (24-158-240-219.dhcp.smyr.ga.charter.com. [24.158.240.219]) by smtp.gmail.com with ESMTPSA id s188sm2633931ywd.7.2019.08.18.12.29.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 18 Aug 2019 12:29:35 -0700 (PDT) From: Wenwen Wang To: Wenwen Wang Cc: Mike Marciniszyn , Dennis Dalessandro , Doug Ledford , Jason Gunthorpe , linux-rdma@vger.kernel.org (open list:HFI1 DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH] infiniband: hfi1: fix a memory leak bug Date: Sun, 18 Aug 2019 14:29:31 -0500 Message-Id: <1566156571-4335-1-git-send-email-wenwen@cs.uga.edu> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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 93613e5..814324d 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.7.4