[dpdk-dev,02/21] net/qede/base: fix to set pointers to NULL after freeing

Message ID 1488181923-9649-2-git-send-email-rasesh.mody@cavium.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers

Checks

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

Commit Message

Mody, Rasesh Feb. 27, 2017, 7:51 a.m. UTC
  Set pointers to NULL after freeing the allocations on ecore_resc_free().

Fixes: 26ae839d06e9 ("qede: add DCBX support")
Fixes: ec94dbc57362 ("qede: add base driver")

Signed-off-by: Rasesh Mody <rasesh.mody@cavium.com>
---
 drivers/net/qede/base/ecore_dcbx.c |    2 +-
 drivers/net/qede/base/ecore_dev.c  |    4 ++--
 drivers/net/qede/base/ecore_spq.c  |    2 ++
 3 files changed, 5 insertions(+), 3 deletions(-)
  

Comments

Ferruh Yigit March 2, 2017, 1:05 p.m. UTC | #1
On 2/27/2017 7:51 AM, Rasesh Mody wrote:
> Set pointers to NULL after freeing the allocations on ecore_resc_free().
> 
> Fixes: 26ae839d06e9 ("qede: add DCBX support")
> Fixes: ec94dbc57362 ("qede: add base driver")
> 
> Signed-off-by: Rasesh Mody <rasesh.mody@cavium.com>
> ---
>  drivers/net/qede/base/ecore_dcbx.c |    2 +-
>  drivers/net/qede/base/ecore_dev.c  |    4 ++--
>  drivers/net/qede/base/ecore_spq.c  |    2 ++
>  3 files changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/net/qede/base/ecore_dcbx.c b/drivers/net/qede/base/ecore_dcbx.c
> index 7380fd8..9ce6dc4 100644
> --- a/drivers/net/qede/base/ecore_dcbx.c
> +++ b/drivers/net/qede/base/ecore_dcbx.c
> @@ -914,7 +914,7 @@ enum _ecore_status_t ecore_dcbx_info_alloc(struct ecore_hwfn *p_hwfn)
>  void ecore_dcbx_info_free(struct ecore_hwfn *p_hwfn,
>  			  struct ecore_dcbx_info *p_dcbx_info)
>  {
> -	OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_dcbx_info);
> +	p_hwfn->p_dcbx_info = OSAL_NULL;


Is replacing free with "NULL assignment" intentional?

From commit log and other updates in this patch, intention looks like
setting pointers to NULL after freeing them.

>  }
>  
>  static void ecore_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
> diff --git a/drivers/net/qede/base/ecore_dev.c b/drivers/net/qede/base/ecore_dev.c
> index 0518fc7..15051b6 100644
> --- a/drivers/net/qede/base/ecore_dev.c
> +++ b/drivers/net/qede/base/ecore_dev.c
> @@ -156,6 +156,7 @@ void ecore_resc_free(struct ecore_dev *p_dev)
>  	p_dev->fw_data = OSAL_NULL;
>  
>  	OSAL_FREE(p_dev, p_dev->reset_stats);
> +	p_dev->reset_stats = OSAL_NULL;

Since already a macro used for free, does it make sense to make NULL
assignment part of macro?
  
Mody, Rasesh March 18, 2017, 7:02 a.m. UTC | #2
> From: Ferruh Yigit [mailto:ferruh.yigit@intel.com]
> Sent: Thursday, March 02, 2017 5:05 AM
> 
> On 2/27/2017 7:51 AM, Rasesh Mody wrote:
> > Set pointers to NULL after freeing the allocations on ecore_resc_free().
> >
> > Fixes: 26ae839d06e9 ("qede: add DCBX support")
> > Fixes: ec94dbc57362 ("qede: add base driver")
> >
> > Signed-off-by: Rasesh Mody <rasesh.mody@cavium.com>
> > ---
> >  drivers/net/qede/base/ecore_dcbx.c |    2 +-
> >  drivers/net/qede/base/ecore_dev.c  |    4 ++--
> >  drivers/net/qede/base/ecore_spq.c  |    2 ++
> >  3 files changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/net/qede/base/ecore_dcbx.c
> > b/drivers/net/qede/base/ecore_dcbx.c
> > index 7380fd8..9ce6dc4 100644
> > --- a/drivers/net/qede/base/ecore_dcbx.c
> > +++ b/drivers/net/qede/base/ecore_dcbx.c
> > @@ -914,7 +914,7 @@ enum _ecore_status_t
> ecore_dcbx_info_alloc(struct
> > ecore_hwfn *p_hwfn)  void ecore_dcbx_info_free(struct ecore_hwfn
> *p_hwfn,
> >  			  struct ecore_dcbx_info *p_dcbx_info)  {
> > -	OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_dcbx_info);
> > +	p_hwfn->p_dcbx_info = OSAL_NULL;
> 
> 
> Is replacing free with "NULL assignment" intentional?

It was an oversight, good catch, incorporated in v2 series, thanks.
> 
> From commit log and other updates in this patch, intention looks like
> setting pointers to NULL after freeing them.
> 
> >  }
> >
> >  static void ecore_dcbx_update_protocol_data(struct protocol_dcb_data
> *p_data,
> > diff --git a/drivers/net/qede/base/ecore_dev.c
> b/drivers/net/qede/base/ecore_dev.c
> > index 0518fc7..15051b6 100644
> > --- a/drivers/net/qede/base/ecore_dev.c
> > +++ b/drivers/net/qede/base/ecore_dev.c
> > @@ -156,6 +156,7 @@ void ecore_resc_free(struct ecore_dev *p_dev)
> >  	p_dev->fw_data = OSAL_NULL;
> >
> >  	OSAL_FREE(p_dev, p_dev->reset_stats);
> > +	p_dev->reset_stats = OSAL_NULL;
> 
> Since already a macro used for free, does it make sense to make NULL
> assignment part of macro?

Incorporated in v2 series.
  

Patch

diff --git a/drivers/net/qede/base/ecore_dcbx.c b/drivers/net/qede/base/ecore_dcbx.c
index 7380fd8..9ce6dc4 100644
--- a/drivers/net/qede/base/ecore_dcbx.c
+++ b/drivers/net/qede/base/ecore_dcbx.c
@@ -914,7 +914,7 @@  enum _ecore_status_t ecore_dcbx_info_alloc(struct ecore_hwfn *p_hwfn)
 void ecore_dcbx_info_free(struct ecore_hwfn *p_hwfn,
 			  struct ecore_dcbx_info *p_dcbx_info)
 {
-	OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_dcbx_info);
+	p_hwfn->p_dcbx_info = OSAL_NULL;
 }
 
 static void ecore_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
diff --git a/drivers/net/qede/base/ecore_dev.c b/drivers/net/qede/base/ecore_dev.c
index 0518fc7..15051b6 100644
--- a/drivers/net/qede/base/ecore_dev.c
+++ b/drivers/net/qede/base/ecore_dev.c
@@ -156,6 +156,7 @@  void ecore_resc_free(struct ecore_dev *p_dev)
 	p_dev->fw_data = OSAL_NULL;
 
 	OSAL_FREE(p_dev, p_dev->reset_stats);
+	p_dev->reset_stats = OSAL_NULL;
 
 	for_each_hwfn(p_dev, i) {
 		struct ecore_hwfn *p_hwfn = &p_dev->hwfns[i];
@@ -668,8 +669,7 @@  enum _ecore_status_t ecore_resc_alloc(struct ecore_dev *p_dev)
 			DP_ERR(p_hwfn, "Cannot allocate 0x%x EQ elements."
 				       "The maximum of a u16 chain is 0x%x\n",
 			       n_eqes, 0xFFFF);
-			rc = ECORE_INVAL;
-			goto alloc_err;
+			goto alloc_no_mem;
 		}
 
 		p_eq = ecore_eq_alloc(p_hwfn, (u16)n_eqes);
diff --git a/drivers/net/qede/base/ecore_spq.c b/drivers/net/qede/base/ecore_spq.c
index 1f35d6c..d55a448 100644
--- a/drivers/net/qede/base/ecore_spq.c
+++ b/drivers/net/qede/base/ecore_spq.c
@@ -402,6 +402,7 @@  void ecore_eq_free(struct ecore_hwfn *p_hwfn, struct ecore_eq *p_eq)
 		return;
 	ecore_chain_free(p_hwfn->p_dev, &p_eq->chain);
 	OSAL_FREE(p_hwfn->p_dev, p_eq);
+	p_eq = OSAL_NULL;
 }
 
 /***************************************************************************
@@ -987,4 +988,5 @@  void ecore_consq_free(struct ecore_hwfn *p_hwfn, struct ecore_consq *p_consq)
 		return;
 	ecore_chain_free(p_hwfn->p_dev, &p_consq->chain);
 	OSAL_FREE(p_hwfn->p_dev, p_consq);
+	p_consq = OSAL_NULL;
 }