From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by dpdk.org (Postfix) with ESMTP id F0A6D1B5FA for ; Tue, 18 Dec 2018 08:16:33 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 Dec 2018 23:16:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,367,1539673200"; d="scan'208";a="303072848" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga006.fm.intel.com with ESMTP; 17 Dec 2018 23:16:32 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.408.0; Mon, 17 Dec 2018 23:16:32 -0800 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.203]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.59]) with mapi id 14.03.0415.000; Tue, 18 Dec 2018 15:16:30 +0800 From: "Xu, Rosen" To: "Pei, Andy" , "dev@dpdk.org" CC: "Pei, Andy" , "Xu, Rosen" , "Zhang, Tianfei" Thread-Topic: [dpdk-dev] [PATCH] Fix a memnory leak bug due to malloc unproperly. Thread-Index: AQHUktC1i88nf8yukkeGsiB6hTfl+KWEG79g Date: Tue, 18 Dec 2018 07:16:30 +0000 Message-ID: <0E78D399C70DA940A335608C6ED296D73A448B65@SHSMSX104.ccr.corp.intel.com> References: <1544725998-70149-1-git-send-email-andy.pei@intel.com> In-Reply-To: <1544725998-70149-1-git-send-email-andy.pei@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZDM3NDY5YWYtZjFkMC00YjgwLTk0ZGItY2YyMTBlZmQ0MTAxIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoicGJEdkxDUHFSMWxuRnNtcXBScUVvVDk2UDF1ODUyNnY3ckVrZzNmbisrKzdiUzJXclZONTdwd1p0RFByKzQ3TCJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH] Fix a memnory leak bug due to malloc unproperly. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Dec 2018 07:16:34 -0000 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 > Subject: [dpdk-dev] [PATCH] Fix a memnory leak bug due to malloc > unproperly. Miss some descriptions about this patch. > Signed-off-by: AndyPei 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(-) >=20 > 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) } >=20 > /** > - * 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 =3D data; > + adapter->name =3D name; > + adapter->ops =3D 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; >=20 > - TAILQ_INIT(&adapter->acc_list); > - adapter->data =3D data; > - adapter->name =3D name; > - adapter->ops =3D match_ops(adapter); > + if (opae_adapter_init(adapter, name, data)) > + return NULL; >=20 > 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) >=20 > +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) >=20 > 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 =3D pci_dev->id.device_id; > data->vendor_id =3D pci_dev->id.vendor_id; >=20 > + adapter =3D rawdev->dev_private; > /* create a opae_adapter based on above device data */ > - adapter =3D opae_adapter_alloc(pci_dev->device.name, data); > - if (!adapter) { > + ret =3D opae_adapter_init(adapter, pci_dev->device.name, data); > + if (ret) { > ret =3D -ENOMEM; > goto free_adapter_data; > } > @@ -420,8 +421,6 @@ > rawdev->device =3D &pci_dev->device; > rawdev->driver_name =3D pci_dev->device.driver->name; >=20 > - rawdev->dev_private =3D adapter; > - > /* must enumerate the adapter before use it */ > ret =3D opae_adapter_enumerate(adapter); > if (ret) > -- > 1.8.3.1