[v5,4/4] net/ice: fix wild pointer

Message ID 20191113013758.39664-5-shougangx.wang@intel.com (mailing list archive)
State Accepted, archived
Delegated to: xiaolong ye
Headers
Series net/ice: fix memory release in FDIR |

Checks

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

Commit Message

Shougang Wang Nov. 13, 2019, 1:37 a.m. UTC
  To avoid wild pointer, pointers should be set to NULL after free them.

Fixes: 1a2fc1799f09 ("net/ice: reject duplicated flow for flow director")
Fixes: 84dc7a95a2d3 ("net/ice: enable flow director engine")
Fixes: 0f880c3df192 ("net/ice: add flow director counter resource init/release")

Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
---
 drivers/net/ice/ice_fdir_filter.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
  

Comments

Qiming Yang Nov. 13, 2019, 8:44 a.m. UTC | #1
Hi,

> -----Original Message-----
> From: Wang, ShougangX
> Sent: Wednesday, November 13, 2019 9:38 AM
> To: dev@dpdk.org
> Cc: Yang, Qiming <qiming.yang@intel.com>; Zhang, Qi Z
> <qi.z.zhang@intel.com>; Wang, ShougangX <shougangx.wang@intel.com>
> Subject: [PATCH v5 4/4] net/ice: fix wild pointer
> 
> To avoid wild pointer, pointers should be set to NULL after free them.
> 
> Fixes: 1a2fc1799f09 ("net/ice: reject duplicated flow for flow director")
> Fixes: 84dc7a95a2d3 ("net/ice: enable flow director engine")
> Fixes: 0f880c3df192 ("net/ice: add flow director counter resource
> init/release")
> 
> Signed-off-by: Wang ShougangX <shougangx.wang@intel.com>
> ---
>  drivers/net/ice/ice_fdir_filter.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
> index e3b633e23..dd0e1b0c9 100644
> --- a/drivers/net/ice/ice_fdir_filter.c
> +++ b/drivers/net/ice/ice_fdir_filter.c
> @@ -167,9 +167,14 @@ ice_fdir_prof_alloc(struct ice_hw *hw)
>  fail_mem:
>  	for (fltr_ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
>  	     fltr_ptype < ptype;
> -	     fltr_ptype++)
> +	     fltr_ptype++) {
>  		rte_free(hw->fdir_prof[fltr_ptype]);
> +		hw->fdir_prof[fltr_ptype] = NULL;
> +	}
> +
>  	rte_free(hw->fdir_prof);
> +	hw->fdir_prof = NULL;
> +
>  	return -ENOMEM;
>  }
> 
> @@ -249,8 +254,10 @@ ice_fdir_counter_release(struct ice_pf *pf)
>  				&fdir_info->counter;
>  	uint8_t i;
> 
> -	for (i = 0; i < container->index_free; i++)
> +	for (i = 0; i < container->index_free; i++) {
>  		rte_free(container->pools[i]);
> +		container->pools[i] = NULL;
> +	}
> 
>  	TAILQ_INIT(&container->pool_list);
>  	container->index_free = 0;
> @@ -400,6 +407,9 @@ ice_fdir_release_filter_list(struct ice_pf *pf)
>  		rte_free(fdir_info->hash_map);
>  	if (fdir_info->hash_table)
>  		rte_hash_free(fdir_info->hash_table);
> +
> +	fdir_info->hash_map = NULL;
> +	fdir_info->hash_table = NULL;
>  }
> 
>  /*
> @@ -526,10 +536,13 @@ ice_fdir_prof_free(struct ice_hw *hw)
> 
>  	for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
>  	     ptype < ICE_FLTR_PTYPE_MAX;
> -	     ptype++)
> +	     ptype++) {
>  		rte_free(hw->fdir_prof[ptype]);
> +		hw->fdir_prof[ptype] = NULL;
> +	}
> 
>  	rte_free(hw->fdir_prof);
> +	hw->fdir_prof = NULL;
>  }
> 
>  /* Remove a profile for some filter type */
> --
> 2.17.1

Acked-by: Qiming Yang <qiming.yang@intel.com>
  

Patch

diff --git a/drivers/net/ice/ice_fdir_filter.c b/drivers/net/ice/ice_fdir_filter.c
index e3b633e23..dd0e1b0c9 100644
--- a/drivers/net/ice/ice_fdir_filter.c
+++ b/drivers/net/ice/ice_fdir_filter.c
@@ -167,9 +167,14 @@  ice_fdir_prof_alloc(struct ice_hw *hw)
 fail_mem:
 	for (fltr_ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
 	     fltr_ptype < ptype;
-	     fltr_ptype++)
+	     fltr_ptype++) {
 		rte_free(hw->fdir_prof[fltr_ptype]);
+		hw->fdir_prof[fltr_ptype] = NULL;
+	}
+
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
+
 	return -ENOMEM;
 }
 
@@ -249,8 +254,10 @@  ice_fdir_counter_release(struct ice_pf *pf)
 				&fdir_info->counter;
 	uint8_t i;
 
-	for (i = 0; i < container->index_free; i++)
+	for (i = 0; i < container->index_free; i++) {
 		rte_free(container->pools[i]);
+		container->pools[i] = NULL;
+	}
 
 	TAILQ_INIT(&container->pool_list);
 	container->index_free = 0;
@@ -400,6 +407,9 @@  ice_fdir_release_filter_list(struct ice_pf *pf)
 		rte_free(fdir_info->hash_map);
 	if (fdir_info->hash_table)
 		rte_hash_free(fdir_info->hash_table);
+
+	fdir_info->hash_map = NULL;
+	fdir_info->hash_table = NULL;
 }
 
 /*
@@ -526,10 +536,13 @@  ice_fdir_prof_free(struct ice_hw *hw)
 
 	for (ptype = ICE_FLTR_PTYPE_NONF_NONE + 1;
 	     ptype < ICE_FLTR_PTYPE_MAX;
-	     ptype++)
+	     ptype++) {
 		rte_free(hw->fdir_prof[ptype]);
+		hw->fdir_prof[ptype] = NULL;
+	}
 
 	rte_free(hw->fdir_prof);
+	hw->fdir_prof = NULL;
 }
 
 /* Remove a profile for some filter type */