[v2] net/netvsc: fix txq leak in error path

Message ID 1602036385-10760-1-git-send-email-wangyunjian@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v2] 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-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/travis-robot success Travis build: passed
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Yunjian Wang Oct. 7, 2020, 2:06 a.m. UTC
  From: Yunjian Wang <wangyunjian@huawei.com>

In hn_dev_tx_queue_setup() allocated memory for txq, we don't free it
when error happens and it will lead to memory leak.

We can check for tx_free_thresh at the beginning of the function to
fix it, before calling txq = rte_zmalloc_socket().

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

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
v2:
  fix code styles suggested by Long Li
---
 drivers/net/netvsc/hn_rxtx.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
  

Comments

Long Li Oct. 9, 2020, 3:53 a.m. UTC | #1
>Subject: [dpdk-dev] [PATCH v2] 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 don't free it
>when error happens and it will lead to memory leak.
>
>We can check for tx_free_thresh at the beginning of the function to fix it,
>before calling txq = rte_zmalloc_socket().
>
>Fixes: cc0251813277 ("net/netvsc: split send buffers from Tx descriptors")
>Cc: stable@dpdk.org
>
>Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>

Acked-by: Long Li <longli@microsoft.com>
>---
>v2:
>  fix code styles suggested by Long Li
>---
> drivers/net/netvsc/hn_rxtx.c | 19 +++++++++----------
> 1 file changed, 9 insertions(+), 10 deletions(-)
>
>diff --git a/drivers/net/netvsc/hn_rxtx.c b/drivers/net/netvsc/hn_rxtx.c
>index 65f1abae5..5d59db513 100644
>--- a/drivers/net/netvsc/hn_rxtx.c
>+++ b/drivers/net/netvsc/hn_rxtx.c
>@@ -252,16 +252,6 @@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
>
> 	PMD_INIT_FUNC_TRACE();
>
>-	txq = rte_zmalloc_socket("HN_TXQ", sizeof(*txq),
>RTE_CACHE_LINE_SIZE,
>-				 socket_id);
>-	if (!txq)
>-		return -ENOMEM;
>-
>-	txq->hv = hv;
>-	txq->chan = hv->channels[queue_idx];
>-	txq->port_id = dev->data->port_id;
>-	txq->queue_id = queue_idx;
>-
> 	tx_free_thresh = tx_conf->tx_free_thresh;
> 	if (tx_free_thresh == 0)
> 		tx_free_thresh = RTE_MIN(nb_desc / 4, @@ -276,6 +266,15
>@@ hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
> 		return -EINVAL;
> 	}
>
>+	txq = rte_zmalloc_socket("HN_TXQ", sizeof(*txq),
>RTE_CACHE_LINE_SIZE,
>+				 socket_id);
>+	if (!txq)
>+		return -ENOMEM;
>+
>+	txq->hv = hv;
>+	txq->chan = hv->channels[queue_idx];
>+	txq->port_id = dev->data->port_id;
>+	txq->queue_id = queue_idx;
> 	txq->free_thresh = tx_free_thresh;
>
> 	snprintf(name, sizeof(name),
>--
>2.23.0
  
Ferruh Yigit Oct. 9, 2020, 11:36 a.m. UTC | #2
On 10/9/2020 4:53 AM, Long Li wrote:
>> Subject: [dpdk-dev] [PATCH v2] 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 don't free it
>> when error happens and it will lead to memory leak.
>>
>> We can check for tx_free_thresh at the beginning of the function to fix it,
>> before calling txq = rte_zmalloc_socket().
>>
>> Fixes: cc0251813277 ("net/netvsc: split send buffers from Tx descriptors")
>> Cc: stable@dpdk.org
>>
>> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> 
> Acked-by: Long Li <longli@microsoft.com>
 >

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

Patch

diff --git a/drivers/net/netvsc/hn_rxtx.c b/drivers/net/netvsc/hn_rxtx.c
index 65f1abae5..5d59db513 100644
--- a/drivers/net/netvsc/hn_rxtx.c
+++ b/drivers/net/netvsc/hn_rxtx.c
@@ -252,16 +252,6 @@  hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
 
 	PMD_INIT_FUNC_TRACE();
 
-	txq = rte_zmalloc_socket("HN_TXQ", sizeof(*txq), RTE_CACHE_LINE_SIZE,
-				 socket_id);
-	if (!txq)
-		return -ENOMEM;
-
-	txq->hv = hv;
-	txq->chan = hv->channels[queue_idx];
-	txq->port_id = dev->data->port_id;
-	txq->queue_id = queue_idx;
-
 	tx_free_thresh = tx_conf->tx_free_thresh;
 	if (tx_free_thresh == 0)
 		tx_free_thresh = RTE_MIN(nb_desc / 4,
@@ -276,6 +266,15 @@  hn_dev_tx_queue_setup(struct rte_eth_dev *dev,
 		return -EINVAL;
 	}
 
+	txq = rte_zmalloc_socket("HN_TXQ", sizeof(*txq), RTE_CACHE_LINE_SIZE,
+				 socket_id);
+	if (!txq)
+		return -ENOMEM;
+
+	txq->hv = hv;
+	txq->chan = hv->channels[queue_idx];
+	txq->port_id = dev->data->port_id;
+	txq->queue_id = queue_idx;
 	txq->free_thresh = tx_free_thresh;
 
 	snprintf(name, sizeof(name),