[PATCH can-next] can: raw: remove redundant NULL check before netdev_hold()

Sang-Heon Jeon posted 1 patch 3 weeks, 5 days ago
net/can/raw.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
[PATCH can-next] can: raw: remove redundant NULL check before netdev_hold()
Posted by Sang-Heon Jeon 3 weeks, 5 days ago
netdev_hold() does nothing if dev is NULL, so the check before the call
is redundant.

So remove it. No functional change.

This is the result of running the Coccinelle script from
scripts/coccinelle/free/ifnulldev_put.cocci after commit f83b8a58695c
("coccinelle: ifnulldev_put: update outdated helper names").

Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>
---
 net/can/raw.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/can/raw.c b/net/can/raw.c
index 82d9c0499c95..e1d05a0341eb 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -525,8 +525,7 @@ static int raw_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int len
 		ro->bound = 1;
 		/* bind() ok -> hold a reference for new ro->dev */
 		ro->dev = dev;
-		if (ro->dev)
-			netdev_hold(ro->dev, &ro->dev_tracker, GFP_KERNEL);
+		netdev_hold(ro->dev, &ro->dev_tracker, GFP_KERNEL);
 	}
 
 out_put_dev:
-- 
2.43.0
Re: [PATCH can-next] can: raw: remove redundant NULL check before netdev_hold()
Posted by Oliver Hartkopp 3 weeks, 5 days ago

On 31.08.26 07:20, Sang-Heon Jeon wrote:
> netdev_hold() does nothing if dev is NULL, so the check before the call
> is redundant.
> 
> So remove it. No functional change.
> 
> This is the result of running the Coccinelle script from
> scripts/coccinelle/free/ifnulldev_put.cocci after commit f83b8a58695c
> ("coccinelle: ifnulldev_put: update outdated helper names").
> 
> Signed-off-by: Sang-Heon Jeon <ekffu200098@gmail.com>

Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>

Many thanks!

> ---
>   net/can/raw.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/net/can/raw.c b/net/can/raw.c
> index 82d9c0499c95..e1d05a0341eb 100644
> --- a/net/can/raw.c
> +++ b/net/can/raw.c
> @@ -525,8 +525,7 @@ static int raw_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int len
>   		ro->bound = 1;
>   		/* bind() ok -> hold a reference for new ro->dev */
>   		ro->dev = dev;
> -		if (ro->dev)
> -			netdev_hold(ro->dev, &ro->dev_tracker, GFP_KERNEL);
> +		netdev_hold(ro->dev, &ro->dev_tracker, GFP_KERNEL);
>   	}
>   
>   out_put_dev: