diff mbox series

RDMA/core: Remove NULL check before dev_{put, hold}

Message ID Zi5QgLIt9sblrfYs@octinomon.home (mailing list archive)
State Superseded
Headers show
Series RDMA/core: Remove NULL check before dev_{put, hold} | expand

Commit Message

Jules Irenge April 28, 2024, 1:34 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/infiniband/core/device.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Leon Romanovsky April 30, 2024, 1:21 p.m. UTC | #1
On Sun, Apr 28, 2024 at 02:34:56PM +0100, Jules Irenge wrote:
> Coccinelle reports a warning
> 
> WARNING: NULL check before dev_{put, hold} functions is not needed

Please do it for whole drivers/infiniband/core in one patch, please.

> 
> 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/infiniband/core/device.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
> index 07cb6c5ffda0..84be4bb9b625 100644
> --- a/drivers/infiniband/core/device.c
> +++ b/drivers/infiniband/core/device.c
> @@ -2235,8 +2235,7 @@ struct net_device *ib_device_get_netdev(struct ib_device *ib_dev,
>  		spin_lock(&pdata->netdev_lock);
>  		res = rcu_dereference_protected(
>  			pdata->netdev, lockdep_is_held(&pdata->netdev_lock));
> -		if (res)
> -			dev_hold(res);
> +		dev_hold(res);
>  		spin_unlock(&pdata->netdev_lock);
>  	}
>  
> -- 
> 2.43.2
>
diff mbox series

Patch

diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c
index 07cb6c5ffda0..84be4bb9b625 100644
--- a/drivers/infiniband/core/device.c
+++ b/drivers/infiniband/core/device.c
@@ -2235,8 +2235,7 @@  struct net_device *ib_device_get_netdev(struct ib_device *ib_dev,
 		spin_lock(&pdata->netdev_lock);
 		res = rcu_dereference_protected(
 			pdata->netdev, lockdep_is_held(&pdata->netdev_lock));
-		if (res)
-			dev_hold(res);
+		dev_hold(res);
 		spin_unlock(&pdata->netdev_lock);
 	}