net/ice: fix null pointer dereferences

Message ID 20240301052029.543989-1-wenwux.ma@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Bruce Richardson
Headers
Series net/ice: fix null pointer dereferences |

Checks

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

Commit Message

Ma, WenwuX March 1, 2024, 5:20 a.m. UTC
  This patch fixes two null pointer dereferences detected by
coverity scan.

Coverity issue: 414096
Fixes: 6ccef90ff5d3 ("net/ice: support VSI level bandwidth config")

Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
---
 drivers/net/ice/ice_tm.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
  

Comments

Bruce Richardson March 1, 2024, 10:34 a.m. UTC | #1
On Fri, Mar 01, 2024 at 01:20:29PM +0800, Wenwu Ma wrote:
> This patch fixes two null pointer dereferences detected by
> coverity scan.
> 
> Coverity issue: 414096
> Fixes: 6ccef90ff5d3 ("net/ice: support VSI level bandwidth config")
> 
> Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
> ---
>  drivers/net/ice/ice_tm.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ice/ice_tm.c b/drivers/net/ice/ice_tm.c
> index fbab0b8808..e10ac855f9 100644
> --- a/drivers/net/ice/ice_tm.c
> +++ b/drivers/net/ice/ice_tm.c
> @@ -616,7 +616,10 @@ static int ice_set_node_rate(struct ice_hw *hw,
>  					   ICE_MAX_BW,
>  					   rate);
>  	if (status) {
> -		PMD_DRV_LOG(ERR, "Failed to set max bandwidth for node %u", tm_node->id);
> +		if (tm_node != NULL)
> +			PMD_DRV_LOG(ERR, "Failed to set max bandwidth for node %u", tm_node->id);
> +		else
> +			PMD_DRV_LOG(ERR, "Failed to set max bandwidth");
>  		return -EINVAL;
>  	}
>  
> @@ -630,7 +633,10 @@ static int ice_set_node_rate(struct ice_hw *hw,
>  					   ICE_MIN_BW,
>  					   rate);
>  	if (status) {
> -		PMD_DRV_LOG(ERR, "Failed to set min bandwidth for node %u", tm_node->id);
> +		if (tm_node != NULL)
> +			PMD_DRV_LOG(ERR, "Failed to set min bandwidth for node %u", tm_node->id);
> +		else
> +			PMD_DRV_LOG(ERR, "Failed to set min bandwidth");
>  		return -EINVAL;
>  	}
>  
Hi Wenwu,

I'm not sure that this is the best fix here, since the error message
doesn't seem particularly useful without the node id. Looking at the code,
this is a static function, so non-public, and only called in three places in
rte_tm.c: from ice_cfg_hw_node, ice_do_hierarchy_commit and
ice_reset_nolead_nodes. In all three cases, failure of this function is
immediately followed by a more specific error message from the calling
function. Therefore, I think we can solve the coverity problem by just
deleting the error prints from here completely, and let the callers manage
error reporting.

What do you think?

/Bruce
  
Ma, WenwuX March 4, 2024, 1:43 a.m. UTC | #2
> -----Original Message-----
> From: Richardson, Bruce <bruce.richardson@intel.com>
> Sent: Friday, March 1, 2024 6:35 PM
> To: Ma, WenwuX <wenwux.ma@intel.com>
> Cc: dev@dpdk.org; Jiale, SongX <songx.jiale@intel.com>
> Subject: Re: [PATCH] net/ice: fix null pointer dereferences
> 
> On Fri, Mar 01, 2024 at 01:20:29PM +0800, Wenwu Ma wrote:
> > This patch fixes two null pointer dereferences detected by coverity
> > scan.
> >
> > Coverity issue: 414096
> > Fixes: 6ccef90ff5d3 ("net/ice: support VSI level bandwidth config")
> >
> > Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
> > ---
> >  drivers/net/ice/ice_tm.c | 10 ++++++++--
> >  1 file changed, 8 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/ice/ice_tm.c b/drivers/net/ice/ice_tm.c index
> > fbab0b8808..e10ac855f9 100644
> > --- a/drivers/net/ice/ice_tm.c
> > +++ b/drivers/net/ice/ice_tm.c
> > @@ -616,7 +616,10 @@ static int ice_set_node_rate(struct ice_hw *hw,
> >  					   ICE_MAX_BW,
> >  					   rate);
> >  	if (status) {
> > -		PMD_DRV_LOG(ERR, "Failed to set max bandwidth for
> node %u", tm_node->id);
> > +		if (tm_node != NULL)
> > +			PMD_DRV_LOG(ERR, "Failed to set max bandwidth for
> node %u", tm_node->id);
> > +		else
> > +			PMD_DRV_LOG(ERR, "Failed to set max bandwidth");
> >  		return -EINVAL;
> >  	}
> >
> > @@ -630,7 +633,10 @@ static int ice_set_node_rate(struct ice_hw *hw,
> >  					   ICE_MIN_BW,
> >  					   rate);
> >  	if (status) {
> > -		PMD_DRV_LOG(ERR, "Failed to set min bandwidth for
> node %u", tm_node->id);
> > +		if (tm_node != NULL)
> > +			PMD_DRV_LOG(ERR, "Failed to set min bandwidth for
> node %u", tm_node->id);
> > +		else
> > +			PMD_DRV_LOG(ERR, "Failed to set min bandwidth");
> >  		return -EINVAL;
> >  	}
> >
> Hi Wenwu,
> 
> I'm not sure that this is the best fix here, since the error message doesn't seem
> particularly useful without the node id. Looking at the code, this is a static
> function, so non-public, and only called in three places in
> rte_tm.c: from ice_cfg_hw_node, ice_do_hierarchy_commit and
> ice_reset_nolead_nodes. In all three cases, failure of this function is
> immediately followed by a more specific error message from the calling
> function. Therefore, I think we can solve the coverity problem by just deleting
> the error prints from here completely, and let the callers manage error
> reporting.
> 
> What do you think?
> 
Ok, I will submit a new patch later.

> /Bruce
  

Patch

diff --git a/drivers/net/ice/ice_tm.c b/drivers/net/ice/ice_tm.c
index fbab0b8808..e10ac855f9 100644
--- a/drivers/net/ice/ice_tm.c
+++ b/drivers/net/ice/ice_tm.c
@@ -616,7 +616,10 @@  static int ice_set_node_rate(struct ice_hw *hw,
 					   ICE_MAX_BW,
 					   rate);
 	if (status) {
-		PMD_DRV_LOG(ERR, "Failed to set max bandwidth for node %u", tm_node->id);
+		if (tm_node != NULL)
+			PMD_DRV_LOG(ERR, "Failed to set max bandwidth for node %u", tm_node->id);
+		else
+			PMD_DRV_LOG(ERR, "Failed to set max bandwidth");
 		return -EINVAL;
 	}
 
@@ -630,7 +633,10 @@  static int ice_set_node_rate(struct ice_hw *hw,
 					   ICE_MIN_BW,
 					   rate);
 	if (status) {
-		PMD_DRV_LOG(ERR, "Failed to set min bandwidth for node %u", tm_node->id);
+		if (tm_node != NULL)
+			PMD_DRV_LOG(ERR, "Failed to set min bandwidth for node %u", tm_node->id);
+		else
+			PMD_DRV_LOG(ERR, "Failed to set min bandwidth");
 		return -EINVAL;
 	}