net/ice: fix memory leak

Message ID 20240107204914.483140-1-qi.z.zhang@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Qi Zhang
Headers
Series net/ice: fix memory leak |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/github-robot: build success github build: passed
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-compile-amd64-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-compile-arm64-testing success Testing PASS

Commit Message

Qi Zhang Jan. 7, 2024, 8:49 p.m. UTC
  Free memory for AQ buffer at icd_move_recfg_lan_txq
Free memory for profile list at ice_tm_conf_uninit

Fixes: 8c481c3bb65b ("net/ice: support queue and queue group bandwidth limit")
Cc: stable@dpdk.org

Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
---
 drivers/net/ice/ice_tm.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
  

Comments

Wenjun Wu Jan. 8, 2024, 7:26 a.m. UTC | #1
> -----Original Message-----
> From: Zhang, Qi Z <qi.z.zhang@intel.com>
> Sent: Monday, January 8, 2024 4:49 AM
> To: Yang, Qiming <qiming.yang@intel.com>; Wu, Wenjun1
> <wenjun1.wu@intel.com>
> Cc: dev@dpdk.org; Zhang, Qi Z <qi.z.zhang@intel.com>; stable@dpdk.org
> Subject: [PATCH] net/ice: fix memory leak
> 
> Free memory for AQ buffer at icd_move_recfg_lan_txq Free memory for
> profile list at ice_tm_conf_uninit
> 
> Fixes: 8c481c3bb65b ("net/ice: support queue and queue group bandwidth
> limit")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
> ---
>  drivers/net/ice/ice_tm.c | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/drivers/net/ice/ice_tm.c b/drivers/net/ice/ice_tm.c index
> b570798f07..c00ecb6a97 100644
> --- a/drivers/net/ice/ice_tm.c
> +++ b/drivers/net/ice/ice_tm.c
> @@ -59,8 +59,15 @@ void
>  ice_tm_conf_uninit(struct rte_eth_dev *dev)  {
>  	struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
> +	struct ice_tm_shaper_profile *shaper_profile;
>  	struct ice_tm_node *tm_node;
> 
> +	/* clear profile */
> +	while ((shaper_profile = TAILQ_FIRST(&pf-
> >tm_conf.shaper_profile_list))) {
> +		TAILQ_REMOVE(&pf->tm_conf.shaper_profile_list,
> shaper_profile, node);
> +		rte_free(shaper_profile);
> +	}
> +
>  	/* clear node configuration */
>  	while ((tm_node = TAILQ_FIRST(&pf->tm_conf.queue_list))) {
>  		TAILQ_REMOVE(&pf->tm_conf.queue_list, tm_node, node);
> @@ -636,6 +643,8 @@ static int ice_move_recfg_lan_txq(struct rte_eth_dev
> *dev,
>  	uint16_t buf_size = ice_struct_size(buf, txqs, 1);
> 
>  	buf = (struct ice_aqc_move_txqs_data *)ice_malloc(hw, sizeof(*buf));
> +	if (buf == NULL)
> +		return -ENOMEM;
> 
>  	queue_parent_node = queue_sched_node->parent;
>  	buf->src_teid = queue_parent_node->info.node_teid;
> @@ -647,6 +656,7 @@ static int ice_move_recfg_lan_txq(struct rte_eth_dev
> *dev,
>  					NULL, buf, buf_size, &txqs_moved,
> NULL);
>  	if (ret || txqs_moved == 0) {
>  		PMD_DRV_LOG(ERR, "move lan queue %u failed", queue_id);
> +		rte_free(buf);
>  		return ICE_ERR_PARAM;
>  	}
> 
> @@ -656,12 +666,14 @@ static int ice_move_recfg_lan_txq(struct
> rte_eth_dev *dev,
>  	} else {
>  		PMD_DRV_LOG(ERR, "invalid children number %d for
> queue %u",
>  			    queue_parent_node->num_children, queue_id);
> +		rte_free(buf);
>  		return ICE_ERR_PARAM;
>  	}
>  	dst_node->children[dst_node->num_children++] =
> queue_sched_node;
>  	queue_sched_node->parent = dst_node;
>  	ice_sched_query_elem(hw, queue_sched_node->info.node_teid,
> &queue_sched_node->info);
> 
> +	rte_free(buf);
>  	return ret;
>  }
> 
> --
> 2.31.1

Acked-by: Wenjun Wu <wenjun1.wu@intel.com>
  
Qi Zhang Jan. 8, 2024, 9:53 a.m. UTC | #2
> -----Original Message-----
> From: Wu, Wenjun1 <wenjun1.wu@intel.com>
> Sent: Monday, January 8, 2024 3:27 PM
> To: Zhang, Qi Z <qi.z.zhang@intel.com>; Yang, Qiming
> <qiming.yang@intel.com>
> Cc: dev@dpdk.org; stable@dpdk.org
> Subject: RE: [PATCH] net/ice: fix memory leak
> 
> 
> 
> > -----Original Message-----
> > From: Zhang, Qi Z <qi.z.zhang@intel.com>
> > Sent: Monday, January 8, 2024 4:49 AM
> > To: Yang, Qiming <qiming.yang@intel.com>; Wu, Wenjun1
> > <wenjun1.wu@intel.com>
> > Cc: dev@dpdk.org; Zhang, Qi Z <qi.z.zhang@intel.com>; stable@dpdk.org
> > Subject: [PATCH] net/ice: fix memory leak
> >
> > Free memory for AQ buffer at icd_move_recfg_lan_txq Free memory for
> > profile list at ice_tm_conf_uninit
> >
> > Fixes: 8c481c3bb65b ("net/ice: support queue and queue group bandwidth
> > limit")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Qi Zhang <qi.z.zhang@intel.com>
> > ---
> >  drivers/net/ice/ice_tm.c | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> >
> > diff --git a/drivers/net/ice/ice_tm.c b/drivers/net/ice/ice_tm.c index
> > b570798f07..c00ecb6a97 100644
> > --- a/drivers/net/ice/ice_tm.c
> > +++ b/drivers/net/ice/ice_tm.c
> > @@ -59,8 +59,15 @@ void
> >  ice_tm_conf_uninit(struct rte_eth_dev *dev)  {
> >  	struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data-
> >dev_private);
> > +	struct ice_tm_shaper_profile *shaper_profile;
> >  	struct ice_tm_node *tm_node;
> >
> > +	/* clear profile */
> > +	while ((shaper_profile = TAILQ_FIRST(&pf-
> > >tm_conf.shaper_profile_list))) {
> > +		TAILQ_REMOVE(&pf->tm_conf.shaper_profile_list,
> > shaper_profile, node);
> > +		rte_free(shaper_profile);
> > +	}
> > +
> >  	/* clear node configuration */
> >  	while ((tm_node = TAILQ_FIRST(&pf->tm_conf.queue_list))) {
> >  		TAILQ_REMOVE(&pf->tm_conf.queue_list, tm_node, node);
> @@ -636,6
> > +643,8 @@ static int ice_move_recfg_lan_txq(struct rte_eth_dev *dev,
> >  	uint16_t buf_size = ice_struct_size(buf, txqs, 1);
> >
> >  	buf = (struct ice_aqc_move_txqs_data *)ice_malloc(hw, sizeof(*buf));
> > +	if (buf == NULL)
> > +		return -ENOMEM;
> >
> >  	queue_parent_node = queue_sched_node->parent;
> >  	buf->src_teid = queue_parent_node->info.node_teid;
> > @@ -647,6 +656,7 @@ static int ice_move_recfg_lan_txq(struct
> > rte_eth_dev *dev,
> >  					NULL, buf, buf_size, &txqs_moved,
> NULL);
> >  	if (ret || txqs_moved == 0) {
> >  		PMD_DRV_LOG(ERR, "move lan queue %u failed", queue_id);
> > +		rte_free(buf);
> >  		return ICE_ERR_PARAM;
> >  	}
> >
> > @@ -656,12 +666,14 @@ static int ice_move_recfg_lan_txq(struct
> > rte_eth_dev *dev,
> >  	} else {
> >  		PMD_DRV_LOG(ERR, "invalid children number %d for
> queue %u",
> >  			    queue_parent_node->num_children, queue_id);
> > +		rte_free(buf);
> >  		return ICE_ERR_PARAM;
> >  	}
> >  	dst_node->children[dst_node->num_children++] =
> queue_sched_node;
> >  	queue_sched_node->parent = dst_node;
> >  	ice_sched_query_elem(hw, queue_sched_node->info.node_teid,
> > &queue_sched_node->info);
> >
> > +	rte_free(buf);
> >  	return ret;
> >  }
> >
> > --
> > 2.31.1
> 
> Acked-by: Wenjun Wu <wenjun1.wu@intel.com>

Applied to dpdk-next-net-intel.

Thanks
Qi
  

Patch

diff --git a/drivers/net/ice/ice_tm.c b/drivers/net/ice/ice_tm.c
index b570798f07..c00ecb6a97 100644
--- a/drivers/net/ice/ice_tm.c
+++ b/drivers/net/ice/ice_tm.c
@@ -59,8 +59,15 @@  void
 ice_tm_conf_uninit(struct rte_eth_dev *dev)
 {
 	struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+	struct ice_tm_shaper_profile *shaper_profile;
 	struct ice_tm_node *tm_node;
 
+	/* clear profile */
+	while ((shaper_profile = TAILQ_FIRST(&pf->tm_conf.shaper_profile_list))) {
+		TAILQ_REMOVE(&pf->tm_conf.shaper_profile_list, shaper_profile, node);
+		rte_free(shaper_profile);
+	}
+
 	/* clear node configuration */
 	while ((tm_node = TAILQ_FIRST(&pf->tm_conf.queue_list))) {
 		TAILQ_REMOVE(&pf->tm_conf.queue_list, tm_node, node);
@@ -636,6 +643,8 @@  static int ice_move_recfg_lan_txq(struct rte_eth_dev *dev,
 	uint16_t buf_size = ice_struct_size(buf, txqs, 1);
 
 	buf = (struct ice_aqc_move_txqs_data *)ice_malloc(hw, sizeof(*buf));
+	if (buf == NULL)
+		return -ENOMEM;
 
 	queue_parent_node = queue_sched_node->parent;
 	buf->src_teid = queue_parent_node->info.node_teid;
@@ -647,6 +656,7 @@  static int ice_move_recfg_lan_txq(struct rte_eth_dev *dev,
 					NULL, buf, buf_size, &txqs_moved, NULL);
 	if (ret || txqs_moved == 0) {
 		PMD_DRV_LOG(ERR, "move lan queue %u failed", queue_id);
+		rte_free(buf);
 		return ICE_ERR_PARAM;
 	}
 
@@ -656,12 +666,14 @@  static int ice_move_recfg_lan_txq(struct rte_eth_dev *dev,
 	} else {
 		PMD_DRV_LOG(ERR, "invalid children number %d for queue %u",
 			    queue_parent_node->num_children, queue_id);
+		rte_free(buf);
 		return ICE_ERR_PARAM;
 	}
 	dst_node->children[dst_node->num_children++] = queue_sched_node;
 	queue_sched_node->parent = dst_node;
 	ice_sched_query_elem(hw, queue_sched_node->info.node_teid, &queue_sched_node->info);
 
+	rte_free(buf);
 	return ret;
 }