From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 38873A0540;
	Mon,  4 Jul 2022 17:27:51 +0200 (CEST)
Received: from [217.70.189.124] (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id 1E6A142B6F;
	Mon,  4 Jul 2022 17:27:41 +0200 (CEST)
Received: from mga12.intel.com (mga12.intel.com [192.55.52.136])
 by mails.dpdk.org (Postfix) with ESMTP id F422A410E5;
 Mon,  4 Jul 2022 17:27:37 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
 d=intel.com; i=@intel.com; q=dns/txt; s=Intel;
 t=1656948458; x=1688484458;
 h=from:to:cc:subject:date:message-id:in-reply-to:
 references:mime-version:content-transfer-encoding;
 bh=vzNee63WJBwbDCVa81Njrjgevg5hmTVjSaZRO4wjgV8=;
 b=KiaOfasebiHDLNWz+TsN3hP9qzsuzZntfHcjzYmzOWtgXC77CkXoIlJv
 bujXo1p6cBg/hYsGCq6xUqGkBUct/OpSv4LcuB98l0cAu/hCl9iN4qp2h
 0ZAumiXu3Wy8uuHM/cPOV52zyShAYxt80nEjC9YxG4fDBWk5w8m4XCThM
 lV080H+FW1nX/JsBvsZ9jwPtnO1YoTeVzL1eRn+DMMDo8+yQwOLD96zXh
 hYElaG1Neq5tfm4we+TFfo65lybohTMd7uPPEk1K9L2gbHu4r8es78B4S
 kbcngdrXLqPSK/68ia+lDaY0CrhwusVwpp0TSNCwzD9/yxtZ0eZSXr27D Q==;
X-IronPort-AV: E=McAfee;i="6400,9594,10398"; a="262946839"
X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="262946839"
Received: from fmsmga003.fm.intel.com ([10.253.24.29])
 by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;
 04 Jul 2022 08:27:11 -0700
X-ExtLoop1: 1
X-IronPort-AV: E=Sophos;i="5.92,243,1650956400"; d="scan'208";a="682231011"
Received: from silpixa00401122.ir.intel.com ([10.237.213.29])
 by FMSMGA003.fm.intel.com with ESMTP; 04 Jul 2022 08:27:10 -0700
From: Kevin Laatz <kevin.laatz@intel.com>
To: dev@dpdk.org
Cc: bruce.richardson@intel.com, Kevin Laatz <kevin.laatz@intel.com>,
 stable@dpdk.org
Subject: [PATCH v3 2/3] dma/idxd: fix memory leak due to free on incorrect
 pointer
Date: Mon,  4 Jul 2022 16:27:50 +0100
Message-Id: <20220704152751.943965-3-kevin.laatz@intel.com>
X-Mailer: git-send-email 2.31.1
In-Reply-To: <20220704152751.943965-1-kevin.laatz@intel.com>
References: <20220408141504.1319913-1-kevin.laatz@intel.com>
 <20220704152751.943965-1-kevin.laatz@intel.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

During PCI device close, any allocated memory needs to be free'd.
Currently, one of the free's is being called on an incorrect idxd_dmadev
struct member, namely 'batch_idx_ring'.

At device creation, memory is allocated for both 'batch_comp_ring' and
'batch_idx_ring' simultaeneously. Calling free only on 'batch_idx_ring'
meant the first half of this memory was not being free'd, leading to the
memleak.

This patch fixes this memleak by calling free on 'batch_comp_ring' which
will free the memory for both rings.

Fixes: 9449330a8458 ("dma/idxd: create dmadev instances on PCI probe")
Cc: stable@dpdk.org
Cc: bruce.richardson@intel.com

Signed-off-by: Kevin Laatz <kevin.laatz@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
---
 drivers/dma/idxd/idxd_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/dma/idxd/idxd_pci.c b/drivers/dma/idxd/idxd_pci.c
index fb618d34b6..2c3b01cd2b 100644
--- a/drivers/dma/idxd/idxd_pci.c
+++ b/drivers/dma/idxd/idxd_pci.c
@@ -130,7 +130,7 @@ idxd_pci_dev_close(struct rte_dma_dev *dev)
 
 	/* free device memory */
 	IDXD_PMD_DEBUG("Freeing device driver memory");
-	rte_free(idxd->batch_idx_ring);
+	rte_free(idxd->batch_comp_ring);
 	rte_free(idxd->desc_ring);
 
 	/* if this is the last WQ on the device, disable the device and free
-- 
2.31.1