net/netvsc: fix txq leak in error path

Message ID bbe208ba281538f00662908f8e48cfb12c9fd850.1601369660.git.wangyunjian@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series net/netvsc: fix txq leak in error path |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-intel-Performance success Performance Testing PASS

Commit Message

Yunjian Wang Sept. 29, 2020, 1:44 p.m. UTC
  From: Yunjian Wang <wangyunjian@huawei.com>

In hn_dev_tx_queue_setup() allocated memory for txq,
we should free it when error happens, otherwise it
will lead to memory leak.

Fixes: cc0251813277 ("net/netvsc: split send buffers from Tx descriptors")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 drivers/net/netvsc/hn_rxtx.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Long Li Sept. 30, 2020, 10:27 p.m. UTC | #1
>Subject: [dpdk-dev] [PATCH] net/netvsc: fix txq leak in error path
>
>From: Yunjian Wang <wangyunjian@huawei.com>
>
>In hn_dev_tx_queue_setup() allocated memory for txq, we should free it
>when error happens, otherwise it will lead to memory leak.
>
>Fixes: cc0251813277 ("net/netvsc: split send buffers from Tx descriptors")
>Cc: stable@dpdk.org
>
>Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
>---
> drivers/net/netvsc/hn_rxtx.c | 1 +
> 1 file changed, 1 insertion(+)
>
>diff --git a/drivers/net/netvsc/hn_rxtx.c b/drivers/net/netvsc/hn_rxtx.c
>index 65f1abae5..8c94e7ee3 100644
>--- a/drivers/net/netvsc/hn_rxtx.c
>+++ b/drivers/net/netvsc/hn_rxtx.c
>@@ -273,6 +273,7 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
> 			     " (tx_free_thresh=%u port=%u queue=%u)\n",
> 			     nb_desc - 3,
> 			     tx_free_thresh, dev->data->port_id, queue_idx);
>+		rte_free(txq);
> 		return -EINVAL;
> 	}
>
>--
>2.23.0

How about checking for tx_free_thresh at the beginning of the function, before calling txq = rte_zmalloc_socket()? 

This way, you don't' need to call rte_free() on error.

Long
  
Yunjian Wang Oct. 2, 2020, 2:25 p.m. UTC | #2
> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Long Li
> Sent: Thursday, October 1, 2020 6:27 AM
> To: wangyunjian <wangyunjian@huawei.com>; dev@dpdk.org
> Cc: Stephen Hemminger <sthemmin@microsoft.com>; KY Srinivasan
> <kys@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>;
> jerry.lilijun@huawei.com; xudingke@huawei.com; stable@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH] net/netvsc: fix txq leak in error path
> 
> >Subject: [dpdk-dev] [PATCH] net/netvsc: fix txq leak in error path
> >
> >From: Yunjian Wang <wangyunjian@huawei.com>
> >
> >In hn_dev_tx_queue_setup() allocated memory for txq, we should free it
> >when error happens, otherwise it will lead to memory leak.
> >
> >Fixes: cc0251813277 ("net/netvsc: split send buffers from Tx
> >descriptors")
> >Cc: stable@dpdk.org
> >
> >Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> >---
> > drivers/net/netvsc/hn_rxtx.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> >diff --git a/drivers/net/netvsc/hn_rxtx.c
> >b/drivers/net/netvsc/hn_rxtx.c index 65f1abae5..8c94e7ee3 100644
> >--- a/drivers/net/netvsc/hn_rxtx.c
> >+++ b/drivers/net/netvsc/hn_rxtx.c
> >@@ -273,6 +273,7 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
> > 			     " (tx_free_thresh=%u port=%u queue=%u)\n",
> > 			     nb_desc - 3,
> > 			     tx_free_thresh, dev->data->port_id, queue_idx);
> >+		rte_free(txq);
> > 		return -EINVAL;
> > 	}
> >
> >--
> >2.23.0
> 
> How about checking for tx_free_thresh at the beginning of the function,
> before calling txq = rte_zmalloc_socket()?
> 
> This way, you don't' need to call rte_free() on error.

OK, I will fix it in next version.

Thanks,
Yunjian

> 
> Long
  

Patch

diff --git a/drivers/net/netvsc/hn_rxtx.c b/drivers/net/netvsc/hn_rxtx.c
index 65f1abae5..8c94e7ee3 100644
--- a/drivers/net/netvsc/hn_rxtx.c
+++ b/drivers/net/netvsc/hn_rxtx.c
@@ -273,6 +273,7 @@  hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
 			     " (tx_free_thresh=%u port=%u queue=%u)\n",
 			     nb_desc - 3,
 			     tx_free_thresh, dev->data->port_id, queue_idx);
+		rte_free(txq);
 		return -EINVAL;
 	}