[dpdk-dev,1/6] i40e: fix problematic dereference

Message ID 1461210177-29330-2-git-send-email-helin.zhang@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Bruce Richardson
Headers

Commit Message

Zhang, Helin April 21, 2016, 3:42 a.m. UTC
  Fix issue reported by Coverity.

Coverity ID 119267: Dereference before null check.

Fixes: 8e109464c022 ("i40e: allow vector Rx and Tx usage")

Signed-off-by: Helin Zhang <helin.zhang@intel.com>
---
 drivers/net/i40e/i40e_rxtx.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
  

Comments

Stephen Hemminger April 21, 2016, 4:10 p.m. UTC | #1
On Thu, 21 Apr 2016 11:42:52 +0800
Helin Zhang <helin.zhang@intel.com> wrote:

> Fix issue reported by Coverity.
> 
> Coverity ID 119267: Dereference before null check.
> 
> Fixes: 8e109464c022 ("i40e: allow vector Rx and Tx usage")
> 
> Signed-off-by: Helin Zhang <helin.zhang@intel.com>
> ---
>  drivers/net/i40e/i40e_rxtx.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c
> index 4d35d83..9c126a3 100644
> --- a/drivers/net/i40e/i40e_rxtx.c
> +++ b/drivers/net/i40e/i40e_rxtx.c
> @@ -2592,14 +2592,14 @@ i40e_rx_queue_release_mbufs(struct i40e_rx_queue *rxq)
>  {
>  	uint16_t i;
>  
> -	/* SSE Vector driver has a different way of releasing mbufs. */
> -	if (rxq->rx_using_sse) {
> -		i40e_rx_queue_release_mbufs_vec(rxq);
> +	if (!rxq || !rxq->sw_ring) {
> +		PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL");
>  		return;
>  	}
>  

I can't see how you could ever trigger this.
 i40e_rx_queue_release_mbufs() is called only called from places where rxq
is guraanteed non NULL.

Are you sure Coverity isn't tell you that?
  
Zhang, Helin April 22, 2016, 1:04 a.m. UTC | #2
> -----Original Message-----
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Friday, April 22, 2016 12:10 AM
> To: Zhang, Helin <helin.zhang@intel.com>
> Cc: dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH 1/6] i40e: fix problematic dereference
> 
> On Thu, 21 Apr 2016 11:42:52 +0800
> Helin Zhang <helin.zhang@intel.com> wrote:
> 
> > Fix issue reported by Coverity.
> >
> > Coverity ID 119267: Dereference before null check.
> >
> > Fixes: 8e109464c022 ("i40e: allow vector Rx and Tx usage")
> >
> > Signed-off-by: Helin Zhang <helin.zhang@intel.com>
> > ---
> >  drivers/net/i40e/i40e_rxtx.c | 10 +++++-----
> >  1 file changed, 5 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/net/i40e/i40e_rxtx.c
> > b/drivers/net/i40e/i40e_rxtx.c index 4d35d83..9c126a3 100644
> > --- a/drivers/net/i40e/i40e_rxtx.c
> > +++ b/drivers/net/i40e/i40e_rxtx.c
> > @@ -2592,14 +2592,14 @@ i40e_rx_queue_release_mbufs(struct
> > i40e_rx_queue *rxq)  {
> >  	uint16_t i;
> >
> > -	/* SSE Vector driver has a different way of releasing mbufs. */
> > -	if (rxq->rx_using_sse) {
> > -		i40e_rx_queue_release_mbufs_vec(rxq);
> > +	if (!rxq || !rxq->sw_ring) {
> > +		PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL");
> >  		return;
> >  	}
> >
> 
> I can't see how you could ever trigger this.
>  i40e_rx_queue_release_mbufs() is called only called from places where rxq is
> guraanteed non NULL.
> 
> Are you sure Coverity isn't tell you that?
Coverity just reported " Dereference before null check ", nothing else there.
The function was called several times in different places. It could be safer, in case
somebody wrongly give the queue id.
But you are right, it shouldn't happen if nothing wrong.

Are you suggesting to remove rxq check? Thanks!

Regards,
Helin
  

Patch

diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c
index 4d35d83..9c126a3 100644
--- a/drivers/net/i40e/i40e_rxtx.c
+++ b/drivers/net/i40e/i40e_rxtx.c
@@ -2592,14 +2592,14 @@  i40e_rx_queue_release_mbufs(struct i40e_rx_queue *rxq)
 {
 	uint16_t i;
 
-	/* SSE Vector driver has a different way of releasing mbufs. */
-	if (rxq->rx_using_sse) {
-		i40e_rx_queue_release_mbufs_vec(rxq);
+	if (!rxq || !rxq->sw_ring) {
+		PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL");
 		return;
 	}
 
-	if (!rxq || !rxq->sw_ring) {
-		PMD_DRV_LOG(DEBUG, "Pointer to rxq or sw_ring is NULL");
+	/* SSE Vector driver has a different way of releasing mbufs. */
+	if (rxq->rx_using_sse) {
+		i40e_rx_queue_release_mbufs_vec(rxq);
 		return;
 	}