Skip to contentSkip to conversation

can: raw: remove redundant NULL check before netdev_hold()

PATCH In review Sang-Heon Jeon 2 participants 2 messages Aug 31

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 can: raw: remove redundant NULL check before netdev_hold()

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").

---
 net/can/raw.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/can/raw.c +1 -2
index 82d9c0499c95..e1d05a0341eb 100644
@@ -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:
Signature · 1 line
2.43.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Sang-Heon Jeon

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").

Many thanks!

Quoted 18 lines
---
  net/can/raw.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
net/can/raw.c +1 -2
index 82d9c0499c95..e1d05a0341eb 100644
@@ -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: