From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by dpdk.org (Postfix) with ESMTP id 6473D1BBDB for ; Wed, 19 Dec 2018 08:16:32 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2018 23:16:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,371,1539673200"; d="scan'208";a="305013309" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga005.fm.intel.com with ESMTP; 18 Dec 2018 23:16:31 -0800 Received: from FMSMSX109.amr.corp.intel.com (10.18.116.9) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 18 Dec 2018 23:16:31 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx109.amr.corp.intel.com (10.18.116.9) with Microsoft SMTP Server (TLS) id 14.3.408.0; Tue, 18 Dec 2018 23:16:30 -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; Wed, 19 Dec 2018 15:16:29 +0800 From: "Xu, Rosen" To: "Pei, Andy" , "dev@dpdk.org" CC: "Zhang, Tianfei" Thread-Topic: [PATCH v2]/driver/raw/ifpga_rawdev: fix a memory leak bug in ifpga Thread-Index: AQHUlscycyS4F9ZyQUqSiNJ+TGC/WaWFprZg Date: Wed, 19 Dec 2018 07:16:28 +0000 Message-ID: <0E78D399C70DA940A335608C6ED296D73A450638@SHSMSX104.ccr.corp.intel.com> References: <1544725998-70149-1-git-send-email-andy.pei@intel.com> <1545161721-382282-1-git-send-email-andy.pei@intel.com> In-Reply-To: <1545161721-382282-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: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNjlkZjJlZjgtMDQ0Ni00ZGZlLTgwZmItMTY0MWQ5NmM5MmQ1IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoidXkrc3h2dmYrV3ZZZWZQU2RTSDRXdlZINzVZOTJWYzhXNVhndlY5Yk1jQW9UU0xYb0JnT0lDMkhKTml2WUVRbiJ9 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 v2]/driver/raw/ifpga_rawdev: fix a memory leak bug in ifpga 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: Wed, 19 Dec 2018 07:16:33 -0000 Hi Andy, > -----Original Message----- > From: Pei, Andy > Sent: Wednesday, December 19, 2018 3:35 > To: dev@dpdk.org > Cc: Xu, Rosen ; Zhang, Tianfei > ; Pei, Andy > Subject: [PATCH v2]/driver/raw/ifpga_rawdev: fix a memory leak bug in ifp= ga >=20 > 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. >=20 > fixes:ef1e8ede3da5 > cc:rosen.xu@intel.com > cc:tianfei.zhang@intel.com >=20 > Signed-off-by: AndyPei > --- > drivers/raw/ifpga_rawdev/base/opae_hw_api.c | 32 > ++++++++++++++++++++++++----- > drivers/raw/ifpga_rawdev/base/opae_hw_api.h | 4 +++- > drivers/raw/ifpga_rawdev/ifpga_rawdev.c | 7 +++---- > 3 files changed, 33 insertions(+), 10 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..50f6438 100644 > --- a/drivers/raw/ifpga_rawdev/base/opae_hw_api.c > +++ b/drivers/raw/ifpga_rawdev/base/opae_hw_api.c > @@ -303,12 +303,35 @@ 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. > * > * Return: opae_adapter on success, otherwise NULL. > */ > + /**This function will no longer be called. > struct opae_adapter *opae_adapter_alloc(const char *name, void *data) { > struct opae_adapter *adapter =3D opae_zmalloc(sizeof(*adapter)); > @@ -316,13 +339,12 @@ 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; > } To avoid redundancy, does this function useful? > +**/ >=20 > /** > * opae_adapter_enumerate - enumerate this adapter diff --git > a/drivers/raw/ifpga_rawdev/base/opae_hw_api.h > b/drivers/raw/ifpga_rawdev/base/opae_hw_api.h > index 4bbc9df..ac1941a 100644 > --- a/drivers/raw/ifpga_rawdev/base/opae_hw_api.h > +++ b/drivers/raw/ifpga_rawdev/base/opae_hw_api.h > @@ -225,7 +225,9 @@ struct opae_adapter { void > *opae_adapter_data_alloc(enum opae_adapter_type type); #define > opae_adapter_data_free(data) opae_free(data) >=20 > -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 *opae_adapter_alloc(const char *name, void > +*data); > #define opae_adapter_free(adapter) opae_free(adapter) >=20 > 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..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; Return error from opae_adapter_init() will cause free data? Do you need to free 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