From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by dpdk.org (Postfix) with ESMTP id 06BFE6CC1 for ; Thu, 13 Dec 2018 11:43:12 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Dec 2018 02:43:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,348,1539673200"; d="scan'208";a="98436909" Received: from dipei-st-npg.sh.intel.com ([10.67.110.220]) by orsmga007.jf.intel.com with ESMTP; 13 Dec 2018 02:43:11 -0800 From: AndyPei To: dev@dpdk.org Cc: andy.pei@intel.com Date: Fri, 14 Dec 2018 02:33:18 +0800 Message-Id: <1544725998-70149-1-git-send-email-andy.pei@intel.com> X-Mailer: git-send-email 1.8.3.1 Subject: [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: Thu, 13 Dec 2018 10:43:13 -0000 Signed-off-by: AndyPei --- 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; } 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