Subject: Re: [PATCH net-next v2] net/mlx5e: Remove NULL check before dev_{put, hold}

From: Leon Romanovsky <[email-masked]>
Date: Tue, 4 Apr 2023 09:01:38 +0300

On Tue, Apr 04, 2023 at 10:11:02AM +0800, Yang Li wrote:
> ./drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:35:2-9: WARNING: NULL check before dev_{put, hold} functions is not needed.
> ./drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:734:2-9: WARNING: NULL check before dev_{put, hold} functions is not needed.
> ./drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:769:2-9: WARNING: NULL check before dev_{put, hold} functions is not needed.
> 
> Reported-by: Abaci Robot <[email-masked]>
> Link: https://bugzilla.openanolis.cn/show_bug.cgi?id=4667
> Signed-off-by: Yang Li <[email-masked]>
> ---
> 
> change in v2:
> --According to Simon's suggestion, add the one in mlx5e_set_int_port_tunnel().

Once you are doing such cleanup, please do it in one pass for whole driver.

➜  kernel git:(net-next) git grep -B1 dev_put drivers/net/ethernet/mellanox/mlx5/core/ | grep if -A1
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c-	if (attr->route_dev)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c:		dev_put(attr->route_dev);
--
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c-	if (uplink_upper)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c:		dev_put(uplink_upper);
--
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c-	if (route_dev)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:		dev_put(route_dev);
--
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c-	if (route_dev)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:		dev_put(route_dev);
--
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c-	if (route_dev)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c:		dev_put(route_dev);

Thanks

> 
>  .../net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c  | 10 +++-------
>  1 file changed, 3 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
> index 20c2d2ecaf93..2cb2ba857155 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c
> @@ -32,9 +32,7 @@ static int mlx5e_set_int_port_tunnel(struct mlx5e_priv *priv,
>  						&attr->action, out_index);
>  
>  out:
> -	if (route_dev)
> -		dev_put(route_dev);
> -
> +	dev_put(route_dev);
>  	return err;
>  }
>  
> @@ -730,8 +728,7 @@ static int mlx5e_set_vf_tunnel(struct mlx5_eswitch *esw,
>  	}
>  
>  out:
> -	if (route_dev)
> -		dev_put(route_dev);
> +	dev_put(route_dev);
>  	return err;
>  }
>  
> @@ -765,8 +762,7 @@ static int mlx5e_update_vf_tunnel(struct mlx5_eswitch *esw,
>  	mlx5e_tc_match_to_reg_mod_hdr_change(esw->dev, mod_hdr_acts, VPORT_TO_REG, act_id, data);
>  
>  out:
> -	if (route_dev)
> -		dev_put(route_dev);
> +	dev_put(route_dev);
>  	return err;
>  }
>  
> -- 
> 2.20.1.7.g153144c
>