* [dpdk-stable] [PATCH v2] raw/ifpga: fix a memory leak bug in /driver/raw/ifpga_rawdev [not found] <1547729224-426571-1-git-send-email-andy.pei@intel.com> @ 2019-01-18 7:16 ` Andy Pei 2019-01-18 11:14 ` [dpdk-stable] [PATCH v3] raw/ifpga: fix memory leak Ferruh Yigit 0 siblings, 1 reply; 3+ messages in thread From: Andy Pei @ 2019-01-18 7:16 UTC (permalink / raw) To: dev; +Cc: andy.pei, rosen.xu, stable 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: andy.pei@intel.com Cc: rosen.xu@intel.com Cc: stable@dpdk.org Signed-off-by: Andy Pei <andy.pei@intel.com> --- v2: * Remove [DPDK] prefix. * Cc: stable@dpdk.org 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 a533dfe..1541b67 100644 --- a/drivers/raw/ifpga_rawdev/base/opae_hw_api.c +++ b/drivers/raw/ifpga_rawdev/base/opae_hw_api.c @@ -303,25 +303,25 @@ 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); adapter->data = data; adapter->name = name; 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 4bbc9df..332e0f3 100644 --- a/drivers/raw/ifpga_rawdev/base/opae_hw_api.h +++ b/drivers/raw/ifpga_rawdev/base/opae_hw_api.h @@ -225,7 +225,8 @@ struct opae_adapter { 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) int opae_adapter_enumerate(struct opae_adapter *adapter); diff --git a/drivers/raw/ifpga_rawdev/ifpga_rawdev.c b/drivers/raw/ifpga_rawdev/ifpga_rawdev.c index 32e318f..da772d0 100644 --- a/drivers/raw/ifpga_rawdev/ifpga_rawdev.c +++ b/drivers/raw/ifpga_rawdev/ifpga_rawdev.c @@ -409,9 +409,10 @@ data->device_id = pci_dev->id.device_id; 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; } @@ -420,12 +421,10 @@ rawdev->device = &pci_dev->device; 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 */ mgr = opae_adapter_get_mgr(adapter); @@ -436,9 +435,6 @@ return ret; -free_adapter: - if (adapter) - opae_adapter_free(adapter); free_adapter_data: if (data) opae_adapter_data_free(data); -- 1.8.3.1 ^ permalink raw reply [flat|nested] 3+ messages in thread
* [dpdk-stable] [PATCH v3] raw/ifpga: fix memory leak 2019-01-18 7:16 ` [dpdk-stable] [PATCH v2] raw/ifpga: fix a memory leak bug in /driver/raw/ifpga_rawdev Andy Pei @ 2019-01-18 11:14 ` Ferruh Yigit 2019-01-18 19:00 ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon 0 siblings, 1 reply; 3+ messages in thread From: Ferruh Yigit @ 2019-01-18 11:14 UTC (permalink / raw) To: dev, Rosen Xu, Tianfei zhang; +Cc: Andy Pei, stable From: Andy Pei <andy.pei@intel.com> 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 <andy.pei@intel.com> Acked-by: Tianfei zhang <tianfei.zhang@intel.com> Acked-by: Rosen Xu <rosen.xu@intel.com> --- Cc: rosen.xu@intel.com --- 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 @@ -303,25 +303,25 @@ 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); adapter->data = data; adapter->name = name; 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 @@ -225,7 +225,8 @@ struct opae_adapter { 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) int opae_adapter_enumerate(struct opae_adapter *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 @@ -409,9 +409,10 @@ ifpga_rawdev_create(struct rte_pci_device *pci_dev, data->device_id = pci_dev->id.device_id; 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; } @@ -420,12 +421,10 @@ ifpga_rawdev_create(struct rte_pci_device *pci_dev, rawdev->device = &pci_dev->device; 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 */ mgr = opae_adapter_get_mgr(adapter); @@ -436,9 +435,6 @@ ifpga_rawdev_create(struct rte_pci_device *pci_dev, return ret; -free_adapter: - if (adapter) - opae_adapter_free(adapter); free_adapter_data: if (data) opae_adapter_data_free(data); -- 2.17.2 ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dpdk-stable] [dpdk-dev] [PATCH v3] raw/ifpga: fix memory leak 2019-01-18 11:14 ` [dpdk-stable] [PATCH v3] raw/ifpga: fix memory leak Ferruh Yigit @ 2019-01-18 19:00 ` Thomas Monjalon 0 siblings, 0 replies; 3+ messages in thread From: Thomas Monjalon @ 2019-01-18 19:00 UTC (permalink / raw) To: Ferruh Yigit, Andy Pei; +Cc: dev, Rosen Xu, Tianfei zhang, stable 18/01/2019 12:14, Ferruh Yigit: > From: Andy Pei <andy.pei@intel.com> > > 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 <andy.pei@intel.com> > Acked-by: Tianfei zhang <tianfei.zhang@intel.com> > Acked-by: Rosen Xu <rosen.xu@intel.com> Applied, thanks ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-01-18 19:00 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <1547729224-426571-1-git-send-email-andy.pei@intel.com> 2019-01-18 7:16 ` [dpdk-stable] [PATCH v2] raw/ifpga: fix a memory leak bug in /driver/raw/ifpga_rawdev Andy Pei 2019-01-18 11:14 ` [dpdk-stable] [PATCH v3] raw/ifpga: fix memory leak Ferruh Yigit 2019-01-18 19:00 ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).