Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2673187ybl; Thu, 29 Aug 2019 11:16:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqwW3+GboCbrvzebN4t7Y3rkaa/5oSLRZbg2pbHQWPfd5L8+x2KwTbhV30XUbt+92SvDCuRA X-Received: by 2002:a62:53c3:: with SMTP id h186mr13156890pfb.178.1567102617470; Thu, 29 Aug 2019 11:16:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567102617; cv=none; d=google.com; s=arc-20160816; b=lfqvPEP5D00ykjippeGpNOM/9SoERACBtfTgIdAyl/G7ks49t0ZMXTcOrAD3WQbSsf PBkh9dEZrInsc8RjlNCxyREpeRziZp869Uig3ebJ+Aq6mL0NTmKMVf0g1aO4I6bC69iG eh2VpZio7+tOs3C1xpIvwkL/CrPeyDBWjvOBTDSP6HwZWKxpF7uNwVURYrOx6jQtS/zC pr6L2zsuX2mAQW5x3mKWYtsk8RwqF7T3YVAfjHD8lhi8IJiXVGnA+xaMjx0gJssYQ1Ff GoyvZFiJug3J/hZ60k25RFcRNfr+/K4GaifePjzSjjSHWrhkxD7eUnrYT2+vwVYkjyzv qPOg== 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=NfYLXKB9KKlZzlzfexzMdRzcWWpFJBgdrU4xGAAg8nU=; b=j0egiAXKRrqGm0nVONZDPkHTEBqGxw2eoAxl0S7Q9Uix4MDxK42Wt6OHPyKBIvn8/N JOXY52uwes/maCiANfgbmZRY6Tzms4nmwcH7Vhra9VtoPltrMpCQLSVVpLjsibNBMnEG Jq6kaQF/b9lju5VPO7nuVAgoN+dhiGXH4LUm5jVwa3x86LHgMN4jyvrWnmTsfGISZXOW mqBpEwacchCBVNo0df9lq2F9RLWZN8sk0JonUwRKDKrp4aGffP+Q2WMtdzew9AlYgBff Mf28m3k1shi0tzgZpCU1MP3zhcWm8g65LUX/pQkeUk7vso6Lp19cyGzjYuQPoDATwr1R lWhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=nzNzCH3S; 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 h124si3549596pfb.204.2019.08.29.11.16.41; Thu, 29 Aug 2019 11:16:57 -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=nzNzCH3S; 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 S1729233AbfH2SPO (ORCPT + 99 others); Thu, 29 Aug 2019 14:15:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:56908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729194AbfH2SPN (ORCPT ); Thu, 29 Aug 2019 14:15:13 -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 6EF092339E; Thu, 29 Aug 2019 18:15:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102512; bh=koxCPy5DUegL9f1JbTv6u/+jKYiW7/zmbZvd+ZOA9lQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nzNzCH3SPq9bWTHecob1o5QITF1REMHQQHN7nZABCVh0z4Y/+SApAuZ1iIRMNwOHa P7ZxEejjVjHmxKz6uW1IV04SaNRwCI3V5AILHOsv8sG0SxhBzFw8UxodtzuMgqBiTx oleYp4Nn4PVwcGqk1qwlNTTynKFnSQgRmwM9URJY= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Wenwen Wang , Leon Romanovsky , Doug Ledford , Sasha Levin , linux-rdma@vger.kernel.org Subject: [PATCH AUTOSEL 5.2 60/76] IB/mlx4: Fix memory leaks Date: Thu, 29 Aug 2019 14:12:55 -0400 Message-Id: <20190829181311.7562-60-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 5c1baaa82cea2c815a5180ded402a7cd455d1810 ] In mlx4_ib_alloc_pv_bufs(), 'tun_qp->tx_ring' is allocated through kcalloc(). However, it is not always deallocated in the following execution if an error occurs, leading to memory leaks. To fix this issue, free 'tun_qp->tx_ring' whenever an error occurs. Signed-off-by: Wenwen Wang Acked-by: Leon Romanovsky Link: https://lore.kernel.org/r/1566159781-4642-1-git-send-email-wenwen@cs.uga.edu Signed-off-by: Doug Ledford Signed-off-by: Sasha Levin --- drivers/infiniband/hw/mlx4/mad.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c index 68c951491a08a..57079110af9b5 100644 --- a/drivers/infiniband/hw/mlx4/mad.c +++ b/drivers/infiniband/hw/mlx4/mad.c @@ -1677,8 +1677,6 @@ static int mlx4_ib_alloc_pv_bufs(struct mlx4_ib_demux_pv_ctx *ctx, tx_buf_size, DMA_TO_DEVICE); kfree(tun_qp->tx_ring[i].buf.addr); } - kfree(tun_qp->tx_ring); - tun_qp->tx_ring = NULL; i = MLX4_NUM_TUNNEL_BUFS; err: while (i > 0) { @@ -1687,6 +1685,8 @@ static int mlx4_ib_alloc_pv_bufs(struct mlx4_ib_demux_pv_ctx *ctx, rx_buf_size, DMA_FROM_DEVICE); kfree(tun_qp->ring[i].addr); } + kfree(tun_qp->tx_ring); + tun_qp->tx_ring = NULL; kfree(tun_qp->ring); tun_qp->ring = NULL; return -ENOMEM; -- 2.20.1