diff mbox series

net/mlx5e: Remove NULL check before dev_{put, hold}

Message ID Zi5NUDItYAyDGdwV@octinomon.home (mailing list archive)
State Not Applicable
Headers show
Series net/mlx5e: Remove NULL check before dev_{put, hold} | expand

Commit Message

Jules Irenge April 28, 2024, 1:21 p.m. UTC
Coccinelle reports a warning

WARNING: NULL check before dev_{put, hold} functions is not needed

The reason is the call netdev_{put, hold} of dev_{put,hold} will check NULL
There is no need to check before using dev_{put, hold}

Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Leon Romanovsky April 30, 2024, 1:16 p.m. UTC | #1
On Sun, Apr 28, 2024 at 02:21:20PM +0100, Jules Irenge wrote:
> Coccinelle reports a warning
> 
> WARNING: NULL check before dev_{put, hold} functions is not needed
> 
> The reason is the call netdev_{put, hold} of dev_{put,hold} will check NULL
> There is no need to check before using dev_{put, hold}
> 
> Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
> ---
>  drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
> index 8dfb57f712b0..f23d7116e6d8 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
> @@ -68,16 +68,14 @@ static int get_route_and_out_devs(struct mlx5e_priv *priv,
>  	 * while holding rcu read lock. Take the net_device for correctness
>  	 * sake.
>  	 */
> -	if (uplink_upper)
> -		dev_hold(uplink_upper);
> +	dev_hold(uplink_upper);

I see same if (..) dev_hold() in drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c too.

>  	rcu_read_unlock();
>  
>  	dst_is_lag_dev = (uplink_upper &&
>  			  netif_is_lag_master(uplink_upper) &&
>  			  real_dev == uplink_upper &&
>  			  mlx5_lag_is_sriov(priv->mdev));
> -	if (uplink_upper)
> -		dev_put(uplink_upper);
> +	dev_put(uplink_upper);

This pattern exists in other places in the same file and others too.

Let's change all of them in one patch.

Thanks

>  
>  	/* if the egress device isn't on the same HW e-switch or
>  	 * it's a LAG device, use the uplink
> -- 
> 2.43.2
> 
>
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
index 8dfb57f712b0..f23d7116e6d8 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c
@@ -68,16 +68,14 @@  static int get_route_and_out_devs(struct mlx5e_priv *priv,
 	 * while holding rcu read lock. Take the net_device for correctness
 	 * sake.
 	 */
-	if (uplink_upper)
-		dev_hold(uplink_upper);
+	dev_hold(uplink_upper);
 	rcu_read_unlock();
 
 	dst_is_lag_dev = (uplink_upper &&
 			  netif_is_lag_master(uplink_upper) &&
 			  real_dev == uplink_upper &&
 			  mlx5_lag_is_sriov(priv->mdev));
-	if (uplink_upper)
-		dev_put(uplink_upper);
+	dev_put(uplink_upper);
 
 	/* if the egress device isn't on the same HW e-switch or
 	 * it's a LAG device, use the uplink