net/fm10k: fix memory leak when Tx thresh check fails

Message ID e5abe80f99d2b28fd4b57a4066bfe9d25a037217.1602056082.git.wangyunjian@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Qi Zhang
Headers
Series net/fm10k: fix memory leak when Tx thresh check fails |

Checks

Context Check Description
ci/checkpatch success coding style 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
ci/Intel-compilation success Compilation OK

Commit Message

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

In fm10k_tx_queue_setup(), we allocate memory for the queue
structure but not released when Tx thresh check fails.

Fixes: 98068e0e044e ("fm10k: add Tx queue setup/release")
Cc: stable@dpdk.org

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 drivers/net/fm10k/fm10k_ethdev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Xiao Wang Oct. 8, 2020, 1:39 a.m. UTC | #1
Hi,

Thanks for the patch.

> -----Original Message-----
> From: wangyunjian <wangyunjian@huawei.com>
> Sent: Wednesday, October 7, 2020 3:37 PM
> To: dev@dpdk.org
> Cc: Zhang, Qi Z <qi.z.zhang@intel.com>; Wang, Xiao W
> <xiao.w.wang@intel.com>; jerry.lilijun@huawei.com;
> xudingke@huawei.com; Yunjian Wang <wangyunjian@huawei.com>;
> stable@dpdk.org
> Subject: [dpdk-dev] [PATCH] net/fm10k: fix memory leak when Tx thresh
> check fails
> 
> From: Yunjian Wang <wangyunjian@huawei.com>
> 
> In fm10k_tx_queue_setup(), we allocate memory for the queue
> structure but not released when Tx thresh check fails.
> 
> Fixes: 98068e0e044e ("fm10k: add Tx queue setup/release")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
>  drivers/net/fm10k/fm10k_ethdev.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/fm10k/fm10k_ethdev.c
> b/drivers/net/fm10k/fm10k_ethdev.c
> index 309637071..c4a6fdf7f 100644
> --- a/drivers/net/fm10k/fm10k_ethdev.c
> +++ b/drivers/net/fm10k/fm10k_ethdev.c
> @@ -2024,8 +2024,10 @@ fm10k_tx_queue_setup(struct rte_eth_dev *dev,
> uint16_t queue_id,
>  	q->ops = &def_txq_ops;
>  	q->tail_ptr = (volatile uint32_t *)
>  		&((uint32_t *)hw->hw_addr)[FM10K_TDT(queue_id)];
> -	if (handle_txconf(q, conf))
> +	if (handle_txconf(q, conf)) {
> +		rte_free(q);
>  		return -EINVAL;
> +	}
> 
>  	/* allocate memory for the software ring */
>  	q->sw_ring = rte_zmalloc_socket("fm10k sw ring",
> --
> 2.23.0

Acked-by: Xiao Wang <xiao.w.wang@intel.com>
  
Qi Zhang Oct. 8, 2020, 4:46 a.m. UTC | #2
> -----Original Message-----
> From: Wang, Xiao W <xiao.w.wang@intel.com>
> Sent: Thursday, October 8, 2020 9:39 AM
> To: wangyunjian <wangyunjian@huawei.com>; dev@dpdk.org
> Cc: Zhang, Qi Z <qi.z.zhang@intel.com>; jerry.lilijun@huawei.com;
> xudingke@huawei.com; stable@dpdk.org
> Subject: RE: [dpdk-dev] [PATCH] net/fm10k: fix memory leak when Tx thresh
> check fails
> 
> Hi,
> 
> Thanks for the patch.
> 
> > -----Original Message-----
> > From: wangyunjian <wangyunjian@huawei.com>
> > Sent: Wednesday, October 7, 2020 3:37 PM
> > To: dev@dpdk.org
> > Cc: Zhang, Qi Z <qi.z.zhang@intel.com>; Wang, Xiao W
> > <xiao.w.wang@intel.com>; jerry.lilijun@huawei.com;
> > xudingke@huawei.com; Yunjian Wang <wangyunjian@huawei.com>;
> > stable@dpdk.org
> > Subject: [dpdk-dev] [PATCH] net/fm10k: fix memory leak when Tx thresh
> > check fails
> >
> > From: Yunjian Wang <wangyunjian@huawei.com>
> >
> > In fm10k_tx_queue_setup(), we allocate memory for the queue structure
> > but not released when Tx thresh check fails.
> >
> > Fixes: 98068e0e044e ("fm10k: add Tx queue setup/release")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> > ---
> >  drivers/net/fm10k/fm10k_ethdev.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/net/fm10k/fm10k_ethdev.c
> > b/drivers/net/fm10k/fm10k_ethdev.c
> > index 309637071..c4a6fdf7f 100644
> > --- a/drivers/net/fm10k/fm10k_ethdev.c
> > +++ b/drivers/net/fm10k/fm10k_ethdev.c
> > @@ -2024,8 +2024,10 @@ fm10k_tx_queue_setup(struct rte_eth_dev *dev,
> > uint16_t queue_id,  q->ops = &def_txq_ops;  q->tail_ptr = (volatile
> > uint32_t *)  &((uint32_t *)hw->hw_addr)[FM10K_TDT(queue_id)];
> > -if (handle_txconf(q, conf))
> > +if (handle_txconf(q, conf)) {
> > +rte_free(q);
> >  return -EINVAL;
> > +}
> >
> >  /* allocate memory for the software ring */  q->sw_ring =
> > rte_zmalloc_socket("fm10k sw ring",
> > --
> > 2.23.0
> 
> Acked-by: Xiao Wang <xiao.w.wang@intel.com>

Applied to dpdk-next-net-intel.

Thanks
Qi
>
  

Patch

diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index 309637071..c4a6fdf7f 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -2024,8 +2024,10 @@  fm10k_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_id,
 	q->ops = &def_txq_ops;
 	q->tail_ptr = (volatile uint32_t *)
 		&((uint32_t *)hw->hw_addr)[FM10K_TDT(queue_id)];
-	if (handle_txconf(q, conf))
+	if (handle_txconf(q, conf)) {
+		rte_free(q);
 		return -EINVAL;
+	}
 
 	/* allocate memory for the software ring */
 	q->sw_ring = rte_zmalloc_socket("fm10k sw ring",