From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by dpdk.org (Postfix) with ESMTP id D4A7D1B536 for ; Thu, 7 Feb 2019 14:28:07 +0100 (CET) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 24950ABB14; Thu, 7 Feb 2019 13:28:07 +0000 (UTC) Received: from ktraynor.remote.csb (unknown [10.33.36.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E2936BF2F; Thu, 7 Feb 2019 13:28:05 +0000 (UTC) From: Kevin Traynor To: Andy Pei Cc: Tianfei Zhang , Rosen Xu , dpdk stable Date: Thu, 7 Feb 2019 13:25:43 +0000 Message-Id: <20190207132614.20538-37-ktraynor@redhat.com> In-Reply-To: <20190207132614.20538-1-ktraynor@redhat.com> References: <20190207132614.20538-1-ktraynor@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 07 Feb 2019 13:28:07 +0000 (UTC) Subject: [dpdk-stable] patch 'raw/ifpga: fix memory leak' has been queued to LTS release 18.11.1 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Feb 2019 13:28:08 -0000 Hi, FYI, your patch has been queued to LTS release 18.11.1 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 02/14/19. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Thanks. Kevin Traynor --- >>From 7e4b72b1d9434fea1c0c4b327897d3ffc5ba1205 Mon Sep 17 00:00:00 2001 From: Andy Pei Date: Fri, 18 Jan 2019 11:14:33 +0000 Subject: [PATCH] raw/ifpga: fix memory leak [ upstream commit 3c69149a21be9f21da4d36bcf851762d81e873c1 ] When ifpga_rawdev_create() allocate memory for a new rawdev, the original code allocate redundant memory for adapter, which is a member of the rawdev. What is actually necessary is the adapter to be initialized, not memory allocated. Fixes: ef1e8ede3da5 ("raw/ifpga: add Intel FPGA bus rawdev driver") Signed-off-by: Andy Pei Acked-by: Tianfei Zhang Acked-by: Rosen Xu --- drivers/raw/ifpga_rawdev/base/opae_hw_api.c | 14 +++++++------- drivers/raw/ifpga_rawdev/base/opae_hw_api.h | 3 ++- drivers/raw/ifpga_rawdev/ifpga_rawdev.c | 12 ++++-------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/drivers/raw/ifpga_rawdev/base/opae_hw_api.c b/drivers/raw/ifpga_rawdev/base/opae_hw_api.c index a533dfea8..1541b6798 100644 --- a/drivers/raw/ifpga_rawdev/base/opae_hw_api.c +++ b/drivers/raw/ifpga_rawdev/base/opae_hw_api.c @@ -304,16 +304,16 @@ static struct opae_adapter_ops *match_ops(struct opae_adapter *adapter) /** - * opae_adapter_data_alloc - alloc opae_adapter_data data structure + * opae_adapter_init - init opae_adapter data structure + * @adapter: pointer of opae_adapter data structure * @name: adapter name. * @data: private data of this adapter. * - * Return: opae_adapter on success, otherwise NULL. + * Return: 0 on success. */ -struct opae_adapter *opae_adapter_alloc(const char *name, void *data) +int opae_adapter_init(struct opae_adapter *adapter, + const char *name, void *data) { - struct opae_adapter *adapter = opae_zmalloc(sizeof(*adapter)); - if (!adapter) - return NULL; + return -ENOMEM; TAILQ_INIT(&adapter->acc_list); @@ -322,5 +322,5 @@ struct opae_adapter *opae_adapter_alloc(const char *name, void *data) adapter->ops = match_ops(adapter); - return adapter; + return 0; } diff --git a/drivers/raw/ifpga_rawdev/base/opae_hw_api.h b/drivers/raw/ifpga_rawdev/base/opae_hw_api.h index 4bbc9df5c..332e0f3f6 100644 --- a/drivers/raw/ifpga_rawdev/base/opae_hw_api.h +++ b/drivers/raw/ifpga_rawdev/base/opae_hw_api.h @@ -226,5 +226,6 @@ void *opae_adapter_data_alloc(enum opae_adapter_type type); #define opae_adapter_data_free(data) opae_free(data) -struct opae_adapter *opae_adapter_alloc(const char *name, void *data); +int opae_adapter_init(struct opae_adapter *adapter, + const char *name, void *data); #define opae_adapter_free(adapter) opae_free(adapter) diff --git a/drivers/raw/ifpga_rawdev/ifpga_rawdev.c b/drivers/raw/ifpga_rawdev/ifpga_rawdev.c index 32e318fc3..da772d026 100644 --- a/drivers/raw/ifpga_rawdev/ifpga_rawdev.c +++ b/drivers/raw/ifpga_rawdev/ifpga_rawdev.c @@ -410,7 +410,8 @@ ifpga_rawdev_create(struct rte_pci_device *pci_dev, data->vendor_id = pci_dev->id.vendor_id; + adapter = rawdev->dev_private; /* create a opae_adapter based on above device data */ - adapter = opae_adapter_alloc(pci_dev->device.name, data); - if (!adapter) { + ret = opae_adapter_init(adapter, pci_dev->device.name, data); + if (ret) { ret = -ENOMEM; goto free_adapter_data; @@ -421,10 +422,8 @@ ifpga_rawdev_create(struct rte_pci_device *pci_dev, rawdev->driver_name = pci_dev->device.driver->name; - rawdev->dev_private = adapter; - /* must enumerate the adapter before use it */ ret = opae_adapter_enumerate(adapter); if (ret) - goto free_adapter; + goto free_adapter_data; /* get opae_manager to rawdev */ @@ -437,7 +436,4 @@ ifpga_rawdev_create(struct rte_pci_device *pci_dev, return ret; -free_adapter: - if (adapter) - opae_adapter_free(adapter); free_adapter_data: if (data) -- 2.19.0 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2019-02-07 13:19:56.406311302 +0000 +++ 0037-raw-ifpga-fix-memory-leak.patch 2019-02-07 13:19:55.000000000 +0000 @@ -1,15 +1,16 @@ -From 3c69149a21be9f21da4d36bcf851762d81e873c1 Mon Sep 17 00:00:00 2001 +From 7e4b72b1d9434fea1c0c4b327897d3ffc5ba1205 Mon Sep 17 00:00:00 2001 From: Andy Pei Date: Fri, 18 Jan 2019 11:14:33 +0000 Subject: [PATCH] raw/ifpga: fix memory leak +[ upstream commit 3c69149a21be9f21da4d36bcf851762d81e873c1 ] + When ifpga_rawdev_create() allocate memory for a new rawdev, the original code allocate redundant memory for adapter, which is a member of the rawdev. What is actually necessary is the adapter to be initialized, not memory allocated. Fixes: ef1e8ede3da5 ("raw/ifpga: add Intel FPGA bus rawdev driver") -Cc: stable@dpdk.org Signed-off-by: Andy Pei Acked-by: Tianfei Zhang