[dpdk-dev] net/tap: fix res cleanup when tap create fails

Message ID 1517847440-42660-1-git-send-email-motih@mellanox.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Moti Haimovsky Feb. 5, 2018, 4:17 p.m. UTC
  This patch complements the partial cleanup done inside
eth_dev_tap_create when the routine failed.
Such a failure left a non-functional device attached to the system.

Fixes: 050fe6e9ff97 ("drivers/net: use ethdev allocation helper for vdev")
Cc: stable@dpdk.org

Signed-off-by: Moti Haimovsky <motih@mellanox.com>
---
 drivers/net/tap/rte_eth_tap.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
  

Comments

Pascal Mazon Feb. 7, 2018, 4 p.m. UTC | #1
Acked-by: Pascal Mazon <pascal.mazon@6wind.com>

On 05/02/2018 17:17, Moti Haimovsky wrote:
> This patch complements the partial cleanup done inside
> eth_dev_tap_create when the routine failed.
> Such a failure left a non-functional device attached to the system.
>
> Fixes: 050fe6e9ff97 ("drivers/net: use ethdev allocation helper for vdev")
> Cc: stable@dpdk.org
>
> Signed-off-by: Moti Haimovsky <motih@mellanox.com>
> ---
>  drivers/net/tap/rte_eth_tap.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
> index dc3847e..8931dec 100644
> --- a/drivers/net/tap/rte_eth_tap.c
> +++ b/drivers/net/tap/rte_eth_tap.c
> @@ -1347,13 +1347,13 @@ enum ioctl_mode {
>  	data = rte_zmalloc_socket(tap_name, sizeof(*data), 0, numa_node);
>  	if (!data) {
>  		RTE_LOG(ERR, PMD, "TAP Failed to allocate data\n");
> -		goto error_exit;
> +		goto error_exit_nodev;
>  	}
>  
>  	dev = rte_eth_vdev_allocate(vdev, sizeof(*pmd));
>  	if (!dev) {
>  		RTE_LOG(ERR, PMD, "TAP Unable to allocate device struct\n");
> -		goto error_exit;
> +		goto error_exit_nodev;
>  	}
>  
>  	pmd = dev->data->dev_private;
> @@ -1524,6 +1524,11 @@ enum ioctl_mode {
>  	tap_flow_implicit_flush(pmd, NULL);
>  
>  error_exit:
> +	if (pmd->ioctl_sock > 0)
> +		close(pmd->ioctl_sock);
> +	rte_eth_dev_release_port(dev);
> +
> +error_exit_nodev:
>  	RTE_LOG(ERR, PMD, "TAP Unable to initialize %s\n",
>  		rte_vdev_device_name(vdev));
>
  
Ferruh Yigit Feb. 8, 2018, 12:28 p.m. UTC | #2
On 2/7/2018 4:00 PM, Pascal Mazon wrote:

> On 05/02/2018 17:17, Moti Haimovsky wrote:
>> This patch complements the partial cleanup done inside
>> eth_dev_tap_create when the routine failed.
>> Such a failure left a non-functional device attached to the system.
>>
>> Fixes: 050fe6e9ff97 ("drivers/net: use ethdev allocation helper for vdev")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Moti Haimovsky <motih@mellanox.com>
>
> Acked-by: Pascal Mazon <pascal.mazon@6wind.com>
>

Applied to dpdk-next-net/master, thanks.
  

Patch

diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c
index dc3847e..8931dec 100644
--- a/drivers/net/tap/rte_eth_tap.c
+++ b/drivers/net/tap/rte_eth_tap.c
@@ -1347,13 +1347,13 @@  enum ioctl_mode {
 	data = rte_zmalloc_socket(tap_name, sizeof(*data), 0, numa_node);
 	if (!data) {
 		RTE_LOG(ERR, PMD, "TAP Failed to allocate data\n");
-		goto error_exit;
+		goto error_exit_nodev;
 	}
 
 	dev = rte_eth_vdev_allocate(vdev, sizeof(*pmd));
 	if (!dev) {
 		RTE_LOG(ERR, PMD, "TAP Unable to allocate device struct\n");
-		goto error_exit;
+		goto error_exit_nodev;
 	}
 
 	pmd = dev->data->dev_private;
@@ -1524,6 +1524,11 @@  enum ioctl_mode {
 	tap_flow_implicit_flush(pmd, NULL);
 
 error_exit:
+	if (pmd->ioctl_sock > 0)
+		close(pmd->ioctl_sock);
+	rte_eth_dev_release_port(dev);
+
+error_exit_nodev:
 	RTE_LOG(ERR, PMD, "TAP Unable to initialize %s\n",
 		rte_vdev_device_name(vdev));