net/mlx5: fix using flow tunnel before null check

Message ID 8a980b235eeba49721dfef9d0f23be375e8958b0.1616741870.git.wangyunjian@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Raslan Darawsheh
Headers
Series net/mlx5: fix using flow tunnel before null check |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/travis-robot success travis build: passed
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-testing success Testing PASS

Commit Message

Yunjian Wang March 26, 2021, 9:37 a.m. UTC
  From: Yunjian Wang <wangyunjian@huawei.com>

Coverity flags that 'ctx->tunnel' variable is used before
it's checked for NULL. This patch fixes this issue.

Coverity issue: 366201
Fixes: 868d2e342cf3 ("net/mlx5: fix tunnel offload hub multi-thread protection")

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
 drivers/net/mlx5/mlx5_flow.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Slava Ovsiienko March 26, 2021, 1:23 p.m. UTC | #1
> -----Original Message-----
> From: wangyunjian <wangyunjian@huawei.com>
> Sent: Friday, March 26, 2021 12:37
> To: dev@dpdk.org
> Cc: Matan Azrad <matan@nvidia.com>; Shahaf Shuler
> <shahafs@nvidia.com>; Slava Ovsiienko <viacheslavo@nvidia.com>;
> jerry.lilijun@huawei.com; chenchanghu@huawei.com; Yunjian Wang
> <wangyunjian@huawei.com>
> Subject: [dpdk-dev] [PATCH] net/mlx5: fix using flow tunnel before null
> check
> 
> From: Yunjian Wang <wangyunjian@huawei.com>
> 
> Coverity flags that 'ctx->tunnel' variable is used before it's checked for NULL.
> This patch fixes this issue.
> 
> Coverity issue: 366201
> Fixes: 868d2e342cf3 ("net/mlx5: fix tunnel offload hub multi-thread
> protection")
> 
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>

Thank you for the patch. I suppose, this one should be the part of 20.11LTS
either. Could you, please, add "cc: stable@dpdk.org" and send v2?

With best regards, Slava


> ---
>  drivers/net/mlx5/mlx5_flow.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
> index d46fc333d1..bb8d09cdef 100644
> --- a/drivers/net/mlx5/mlx5_flow.c
> +++ b/drivers/net/mlx5/mlx5_flow.c
> @@ -7899,10 +7899,11 @@ static void get_tunnel_miss(struct rte_eth_dev
> *dev, void *x)
> 
>  	rte_spinlock_unlock(&thub->sl);
>  	ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
> -	ctx->tunnel->refctn = 1;
>  	rte_spinlock_lock(&thub->sl);
> -	if (ctx->tunnel)
> +	if (ctx->tunnel) {
> +		ctx->tunnel->refctn = 1;
>  		LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
> +	}
>  }
> 
> 
> --
> 2.23.0
  
Yunjian Wang March 27, 2021, 1:50 a.m. UTC | #2
> -----Original Message-----
> From: Slava Ovsiienko [mailto:viacheslavo@nvidia.com]
> Sent: Friday, March 26, 2021 9:24 PM
> To: wangyunjian <wangyunjian@huawei.com>; dev@dpdk.org
> Cc: Matan Azrad <matan@nvidia.com>; Shahaf Shuler <shahafs@nvidia.com>;
> Lilijun (Jerry) <jerry.lilijun@huawei.com>; chenchanghu
> <chenchanghu@huawei.com>
> Subject: RE: [dpdk-dev] [PATCH] net/mlx5: fix using flow tunnel before null check
> 
> > -----Original Message-----
> > From: wangyunjian <wangyunjian@huawei.com>
> > Sent: Friday, March 26, 2021 12:37
> > To: dev@dpdk.org
> > Cc: Matan Azrad <matan@nvidia.com>; Shahaf Shuler
> > <shahafs@nvidia.com>; Slava Ovsiienko <viacheslavo@nvidia.com>;
> > jerry.lilijun@huawei.com; chenchanghu@huawei.com; Yunjian Wang
> > <wangyunjian@huawei.com>
> > Subject: [dpdk-dev] [PATCH] net/mlx5: fix using flow tunnel before
> > null check
> >
> > From: Yunjian Wang <wangyunjian@huawei.com>
> >
> > Coverity flags that 'ctx->tunnel' variable is used before it's checked for NULL.
> > This patch fixes this issue.
> >
> > Coverity issue: 366201
> > Fixes: 868d2e342cf3 ("net/mlx5: fix tunnel offload hub multi-thread
> > protection")
> >
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> Acked-by: Viacheslav Ovsiienko <viacheslavo@nvidia.com>
> 
> Thank you for the patch. I suppose, this one should be the part of 20.11LTS
> either. Could you, please, add "cc: stable@dpdk.org" and send v2?
> 
> With best regards, Slava

OK, I will send v2 with it.

Yunjian

> 
> 
> > ---
> >  drivers/net/mlx5/mlx5_flow.c | 5 +++--
> >  1 file changed, 3 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/mlx5/mlx5_flow.c
> > b/drivers/net/mlx5/mlx5_flow.c index d46fc333d1..bb8d09cdef 100644
> > --- a/drivers/net/mlx5/mlx5_flow.c
> > +++ b/drivers/net/mlx5/mlx5_flow.c
> > @@ -7899,10 +7899,11 @@ static void get_tunnel_miss(struct rte_eth_dev
> > *dev, void *x)
> >
> >  	rte_spinlock_unlock(&thub->sl);
> >  	ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
> > -	ctx->tunnel->refctn = 1;
> >  	rte_spinlock_lock(&thub->sl);
> > -	if (ctx->tunnel)
> > +	if (ctx->tunnel) {
> > +		ctx->tunnel->refctn = 1;
> >  		LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
> > +	}
> >  }
> >
> >
> > --
> > 2.23.0
  

Patch

diff --git a/drivers/net/mlx5/mlx5_flow.c b/drivers/net/mlx5/mlx5_flow.c
index d46fc333d1..bb8d09cdef 100644
--- a/drivers/net/mlx5/mlx5_flow.c
+++ b/drivers/net/mlx5/mlx5_flow.c
@@ -7899,10 +7899,11 @@  static void get_tunnel_miss(struct rte_eth_dev *dev, void *x)
 
 	rte_spinlock_unlock(&thub->sl);
 	ctx->tunnel = mlx5_flow_tunnel_allocate(dev, ctx->app_tunnel);
-	ctx->tunnel->refctn = 1;
 	rte_spinlock_lock(&thub->sl);
-	if (ctx->tunnel)
+	if (ctx->tunnel) {
+		ctx->tunnel->refctn = 1;
 		LIST_INSERT_HEAD(&thub->tunnels, ctx->tunnel, chain);
+	}
 }