DPDK patches and discussions
 help / color / mirror / Atom feed
From: "Xu, Rosen" <rosen.xu@intel.com>
To: "Pei, Andy" <andy.pei@intel.com>, "dev@dpdk.org" <dev@dpdk.org>
Cc: "Pei, Andy" <andy.pei@intel.com>,
	"Xu, Rosen" <rosen.xu@intel.com>,
	"Zhang, Tianfei" <tianfei.zhang@intel.com>
Subject: Re: [dpdk-dev] [PATCH] Fix a memnory leak bug due to malloc unproperly.
Date: Tue, 18 Dec 2018 07:16:30 +0000	[thread overview]
Message-ID: <0E78D399C70DA940A335608C6ED296D73A448B65@SHSMSX104.ccr.corp.intel.com> (raw)
In-Reply-To: <1544725998-70149-1-git-send-email-andy.pei@intel.com>

Hi,

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of AndyPei
> Sent: Friday, December 14, 2018 2:33
> To: dev@dpdk.org
> Cc: Pei, Andy <andy.pei@intel.com>
> Subject: [dpdk-dev] [PATCH] Fix a memnory leak bug due to malloc
> unproperly.

Miss some descriptions about this patch.

> Signed-off-by: AndyPei <andy.pei@intel.com>

It seems like this is a bug fix, so pls add fixline

> ---
>  drivers/raw/ifpga_rawdev/base/opae_hw_api.c | 30
> ++++++++++++++++++++++++-----
> drivers/raw/ifpga_rawdev/base/opae_hw_api.h |  2 ++
>  drivers/raw/ifpga_rawdev/ifpga_rawdev.c     |  7 +++----
>  3 files changed, 30 insertions(+), 9 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..b9cca65 100644
> --- a/drivers/raw/ifpga_rawdev/base/opae_hw_api.c
> +++ b/drivers/raw/ifpga_rawdev/base/opae_hw_api.c
> @@ -303,7 +303,29 @@ 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
> + * @adpdate: pointer of opae_adater data structure
> + * @name: adapter name.
> + * @data: private data of this adapter.
> + *
> + * Return: 0 on success.
> + */
> +int opae_adapter_init(struct opae_adapter *adapter,
> +		const char *name, void *data)
> +{
> +	if (!adapter)
> +		return -ENOMEM;
> +
> +	TAILQ_INIT(&adapter->acc_list);
> +	adapter->data = data;
> +	adapter->name = name;
> +	adapter->ops = match_ops(adapter);
> +
> +	return 0;
> +}
> +
> +/**
> + * opae_adapter_alloc - alloc opae_adapter data structure
>   * @name: adapter name.
>   * @data: private data of this adapter.
>   *
> @@ -316,10 +338,8 @@ struct opae_adapter *opae_adapter_alloc(const
> char *name, void *data)
>  	if (!adapter)
>  		return NULL;
> 
> -	TAILQ_INIT(&adapter->acc_list);
> -	adapter->data = data;
> -	adapter->name = name;
> -	adapter->ops = match_ops(adapter);
> +	if (opae_adapter_init(adapter, name, data))
> +		return NULL;
> 
>  	return adapter;
>  }

The operations of opae_adapter_init() and opae_adapter_alloc() are
same, could you merge these two functions?

> diff --git a/drivers/raw/ifpga_rawdev/base/opae_hw_api.h
> b/drivers/raw/ifpga_rawdev/base/opae_hw_api.h
> index 4bbc9df..86ca771 100644
> --- a/drivers/raw/ifpga_rawdev/base/opae_hw_api.h
> +++ b/drivers/raw/ifpga_rawdev/base/opae_hw_api.h
> @@ -225,6 +225,8 @@ struct opae_adapter {  void
> *opae_adapter_data_alloc(enum opae_adapter_type type);  #define
> opae_adapter_data_free(data) opae_free(data)
> 
> +int opae_adapter_init(struct opae_adapter *adapter,
> +		const char *name, void *data);
>  struct opae_adapter *opae_adapter_alloc(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 32e318f..d433091 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,8 +421,6 @@
>  	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)
> --
> 1.8.3.1

  parent reply	other threads:[~2018-12-18  7:16 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-13 18:33 AndyPei
2018-12-13 14:32 ` Burakov, Anatoly
2018-12-18  7:16 ` Xu, Rosen [this message]
2018-12-18 19:35 ` [dpdk-dev] [PATCH v2]/driver/raw/ifpga_rawdev: fix a memory leak bug in ifpga AndyPei
2018-12-19  7:16   ` Xu, Rosen
2018-12-19  8:42     ` Pei, Andy
2018-12-25 14:02   ` [dpdk-dev] [PATCH v3]/driver/raw/ifpga_rawdev: " AndyPei
2019-01-02  2:47     ` Zhang, Tianfei
2019-01-02  6:52     ` Xu, Rosen
2019-01-15  0:03     ` Thomas Monjalon
2019-01-15  5:38     ` [dpdk-dev] [DPDK] [PATCH v4] raw/ifpga: fix a typo and delete code of unused function Andy Pei
2019-01-16 11:26       ` Xu, Rosen
2019-01-17  5:26       ` [dpdk-dev] [DPDK] " Andy Pei
2019-01-17  5:36         ` Ye Xiaolong
2019-01-17  6:39         ` [dpdk-dev] [DPDK] raw/ifpga: fix a typo Andy Pei
2019-01-17  8:39           ` Xu, Rosen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0E78D399C70DA940A335608C6ED296D73A448B65@SHSMSX104.ccr.corp.intel.com \
    --to=rosen.xu@intel.com \
    --cc=andy.pei@intel.com \
    --cc=dev@dpdk.org \
    --cc=tianfei.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).