From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by dpdk.org (Postfix) with ESMTP id 6ED842BAF for ; Tue, 22 May 2018 17:37:15 +0200 (CEST) Received: by mail-wm0-f66.google.com with SMTP id j5-v6so947179wme.5 for ; Tue, 22 May 2018 08:37:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=RgYHjeCKybqtxHKzQeY6hVOiPzL04xUlxyVetRAbPjM=; b=ofb+LnTh1YaX6WdsikoOoe5fZQcjM3E71XMGuutdo3NIsqj+wMdvHinlq0yCQ/k9uY Wgz/RDk7yq/6w0SkeBW9N+HaVBIkWA/sHdtpfH03EY3SkTBnW4mXwy4fSNdnwzHKGFge DTN8nASxF/y0XWGxv282izVB+Jubsqag/7v2X/SA6XVyn3XKac1vSJofWgPItx//XIKI IRQjJ2CGNA4Bdhzu+WJ/r1dOevYQRodsyvz0ltKjzXqy1qJL+JuCSiqxCdYTmtWLk5ud BmOsm4/+Tiq+SzwSj2I8PAfG9UCXHOa/Qfz4VlhIRGguT/lQffGTdkdUTxZd2/fhQGtH LF/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=RgYHjeCKybqtxHKzQeY6hVOiPzL04xUlxyVetRAbPjM=; b=DhhJEcWvcGYgboabrL77vJCyGD6Mx4aMdPa8Y+f5Aicf8efNIkC/DMvKitkDklv485 9kHMdqIH1sfUu3RIFhkSDQk0M2rkGrTfb7GCzXxgRAiUWQXiyArHtycn6JSne6seclxt T1jtdVGht8fdtPvZwGuMz0BRNMn47vvs195RaAaRHh1lyUGB4yX7nFdNqgez+pYLOkFi +QxyyJ+Si7CwPQwdqBurpfb0ek6ZwVefzyTjntP92f2ksiyJduwOXzWgvmIXBvWSi5hd 0l4O0R5NmSgwGbv6vpi0m/W2TJ/pis7WNbfZZmmmgfbMSc2Gl97HVS3llNUnVImkfirW T43A== X-Gm-Message-State: ALKqPwe6FPEeOnkY+7Bx3udNmDYkTLf4asgCbzrrQbh/z4ZEDHNnI+1+ 15Alry8jWLPfTkHdPSi4LWRkJA== X-Google-Smtp-Source: AB8JxZqW+YeKdrwGWLI37FsK2hZTMx0Y7JswUQB/LLh5zv3Acj2mwseIWmHsaI9Z/IVw1CqHqd9BJQ== X-Received: by 2002:a1c:78b:: with SMTP id 133-v6mr1705234wmh.72.1527003435050; Tue, 22 May 2018 08:37:15 -0700 (PDT) Received: from 6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id 131-v6sm208250wms.34.2018.05.22.08.37.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 May 2018 08:37:14 -0700 (PDT) Date: Tue, 22 May 2018 17:36:59 +0200 From: Adrien Mazarguil To: Shahaf Shuler Cc: Ferruh Yigit , dev@dpdk.org, stable@dpdk.org Message-ID: <20180522153441.31354-1-adrien.mazarguil@6wind.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email 2.11.0 Subject: [dpdk-dev] [PATCH 1/2] net/mlx4: fix minor resource leak during init 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, 22 May 2018 15:37:15 -0000 Temporary IB device context and list are not freed in case of a successful initialization of the device. This issue is caused by the two following commits, the first of which causes initialization to return early, while the second one goes a bit overboard while switching to negative errno values; an internal variable (err) is needed to tell success from failure at the end of the function since rte_errno is not reliable enough. Fixes: f2318196c71a ("net/mlx4: remove limitation on number of instances") Fixes: 9d14b27308a0 ("net/mlx4: standardize on negative errno values") Cc: stable@dpdk.org Signed-off-by: Adrien Mazarguil --- drivers/net/mlx4/mlx4.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/drivers/net/mlx4/mlx4.c b/drivers/net/mlx4/mlx4.c index 9f8ecd072..e604c5b8c 100644 --- a/drivers/net/mlx4/mlx4.c +++ b/drivers/net/mlx4/mlx4.c @@ -589,14 +589,14 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) ibv_dev = list[i]; DEBUG("device opened"); if (mlx4_glue->query_device(attr_ctx, &device_attr)) { - rte_errno = ENODEV; + err = ENODEV; goto error; } INFO("%u port(s) detected", device_attr.phys_port_cnt); conf.ports.present |= (UINT64_C(1) << device_attr.phys_port_cnt) - 1; if (mlx4_args(pci_dev->device.devargs, &conf)) { ERROR("failed to process device arguments"); - rte_errno = EINVAL; + err = EINVAL; goto error; } /* Use all ports when none are defined */ @@ -604,7 +604,7 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) conf.ports.enabled = conf.ports.present; /* Retrieve extended device attributes. */ if (mlx4_glue->query_device_ex(attr_ctx, NULL, &device_attr_ex)) { - rte_errno = ENODEV; + err = ENODEV; goto error; } assert(device_attr.max_sge >= MLX4_MAX_SGE); @@ -623,18 +623,18 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) DEBUG("using port %u", port); ctx = mlx4_glue->open_device(ibv_dev); if (ctx == NULL) { - rte_errno = ENODEV; + err = ENODEV; goto port_error; } /* Check port status. */ err = mlx4_glue->query_port(ctx, port, &port_attr); if (err) { - rte_errno = err; - ERROR("port query failed: %s", strerror(rte_errno)); + err = ENODEV; + ERROR("port query failed: %s", strerror(err)); goto port_error; } if (port_attr.link_layer != IBV_LINK_LAYER_ETHERNET) { - rte_errno = ENOTSUP; + err = ENOTSUP; ERROR("port %d is not configured in Ethernet mode", port); goto port_error; @@ -644,15 +644,16 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) port, mlx4_glue->port_state_str(port_attr.state), port_attr.state); /* Make asynchronous FD non-blocking to handle interrupts. */ - if (mlx4_fd_set_non_blocking(ctx->async_fd) < 0) { + err = mlx4_fd_set_non_blocking(ctx->async_fd); + if (err) { ERROR("cannot make asynchronous FD non-blocking: %s", - strerror(rte_errno)); + strerror(err)); goto port_error; } /* Allocate protection domain. */ pd = mlx4_glue->alloc_pd(ctx); if (pd == NULL) { - rte_errno = ENOMEM; + err = ENOMEM; ERROR("PD allocation failure"); goto port_error; } @@ -661,7 +662,7 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) sizeof(*priv), RTE_CACHE_LINE_SIZE); if (priv == NULL) { - rte_errno = ENOMEM; + err = ENOMEM; ERROR("priv allocation failure"); goto port_error; } @@ -691,9 +692,10 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) DEBUG("FCS stripping toggling is %ssupported", priv->hw_fcs_strip ? "" : "not "); /* Configure the first MAC address by default. */ - if (mlx4_get_mac(priv, &mac.addr_bytes)) { + err = mlx4_get_mac(priv, &mac.addr_bytes); + if (err) { ERROR("cannot get MAC address, is mlx4_en loaded?" - " (rte_errno: %s)", strerror(rte_errno)); + " (error: %s)", strerror(err)); goto port_error; } INFO("port %u MAC address is %02x:%02x:%02x:%02x:%02x:%02x", @@ -726,8 +728,8 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) eth_dev = rte_eth_dev_allocate(name); } if (eth_dev == NULL) { + err = ENOMEM; ERROR("can not allocate rte ethdev"); - rte_errno = ENOMEM; goto port_error; } eth_dev->data->dev_private = priv; @@ -773,8 +775,6 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) rte_eth_dev_release_port(eth_dev); break; } - if (i == device_attr.phys_port_cnt) - return 0; /* * 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 @@ -786,8 +786,9 @@ mlx4_pci_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev) claim_zero(mlx4_glue->close_device(attr_ctx)); if (list) mlx4_glue->free_device_list(list); - assert(rte_errno >= 0); - return -rte_errno; + if (err) + rte_errno = err; + return -err; } static const struct rte_pci_id mlx4_pci_id_map[] = { -- 2.11.0