From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 812BAA0A05; Wed, 20 Jan 2021 09:15:07 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 239CA140D67; Wed, 20 Jan 2021 09:15:06 +0100 (CET) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by mails.dpdk.org (Postfix) with ESMTP id 89EF7140D67 for ; Wed, 20 Jan 2021 09:15:04 +0100 (CET) Received: from Internal Mail-Server by MTLPINE1 (envelope-from michaelba@nvidia.com) with SMTP; 20 Jan 2021 10:15:01 +0200 Received: from nvidia.com (pegasus07.mtr.labs.mlnx [10.210.16.112]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 10K8F1k4004806; Wed, 20 Jan 2021 10:15:01 +0200 From: Michael Baum To: dev@dpdk.org Cc: Matan Azrad , Raslan Darawsheh , David Marchand , stable@dpdk.org Date: Wed, 20 Jan 2021 08:14:51 +0000 Message-Id: <1611130491-19129-3-git-send-email-michaelba@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1611130491-19129-1-git-send-email-michaelba@nvidia.com> References: <1610555333-18961-2-git-send-email-michaelba@nvidia.com> <1611130491-19129-1-git-send-email-michaelba@nvidia.com> Subject: [dpdk-dev] [PATCH v2 2/2] net/mlx4: fix PCI probe error flow X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" In mlx4 PCI probing, there are some validations for the Ethernet device configuration. >From each PCI device the function creates one or two Ethernet devices. When one of validations fails during the creation of the second device, the first device is not freed what caused a memory leak. Free it. Fixes: 7fae69eeff13 ("mlx4: new poll mode driver") Cc: stable@dpdk.org Signed-off-by: Michael Baum Acked-by: Matan Azrad --- drivers/net/mlx4/mlx4.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index 7460afa..495b4fc 100644 --- a/drivers/net/mlx4/mlx4.c +++ b/drivers/net/mlx4/mlx4.c @@ -766,6 +766,7 @@ struct mlx4_conf { struct ibv_context *attr_ctx = NULL; struct ibv_device_attr device_attr; struct ibv_device_attr_ex device_attr_ex; + struct rte_eth_dev *prev_dev = NULL; struct mlx4_conf conf = { .ports.present = 0, .mr_ext_memseg_en = 1, @@ -880,7 +881,7 @@ struct mlx4_conf { ERROR("can not attach rte ethdev"); rte_errno = ENOMEM; err = rte_errno; - goto error; + goto err_secondary; } priv = eth_dev->data->dev_private; if (!priv->verbs_alloc_ctx.enabled) { @@ -889,24 +890,24 @@ struct mlx4_conf { " from Verbs"); rte_errno = ENOTSUP; err = rte_errno; - goto error; + goto err_secondary; } eth_dev->device = &pci_dev->device; eth_dev->dev_ops = &mlx4_dev_sec_ops; err = mlx4_proc_priv_init(eth_dev); if (err) - goto error; + goto err_secondary; /* Receive command fd from primary process. */ err = mlx4_mp_req_verbs_cmd_fd(eth_dev); if (err < 0) { err = rte_errno; - goto error; + goto err_secondary; } /* Remap UAR for Tx queues. */ err = mlx4_tx_uar_init_secondary(eth_dev, err); if (err) { err = rte_errno; - goto error; + goto err_secondary; } /* * Ethdev pointer is still required as input since @@ -918,7 +919,14 @@ struct mlx4_conf { claim_zero(mlx4_glue->close_device(ctx)); rte_eth_copy_pci_info(eth_dev, pci_dev); rte_eth_dev_probing_finish(eth_dev); + prev_dev = eth_dev; continue; +err_secondary: + claim_zero(mlx4_glue->close_device(ctx)); + rte_eth_dev_release_port(eth_dev); + if (prev_dev) + rte_eth_dev_release_port(prev_dev); + break; } /* Check port status. */ err = mlx4_glue->query_port(ctx, port, &port_attr); @@ -1093,6 +1101,7 @@ struct mlx4_conf { priv, mem_event_cb); rte_rwlock_write_unlock(&mlx4_shared_data->mem_event_rwlock); rte_eth_dev_probing_finish(eth_dev); + prev_dev = eth_dev; continue; port_error: rte_free(priv); @@ -1107,14 +1116,10 @@ struct mlx4_conf { eth_dev->data->mac_addrs = NULL; rte_eth_dev_release_port(eth_dev); } + if (prev_dev) + mlx4_dev_close(prev_dev); break; } - /* - * XXX if something went wrong in the loop above, there is a resource - * leak (ctx, pd, priv, dpdk ethdev) but we can do nothing about it as - * long as the dpdk does not provide a way to deallocate a ethdev and a - * way to enumerate the registered ethdevs to free the previous ones. - */ error: if (attr_ctx) claim_zero(mlx4_glue->close_device(attr_ctx)); -- 1.8.3.1