Skip to contentSkip to conversation

can: raw: Remove NULL check before dev_{put, hold}

PATCH In review Jiapeng Chong 3 participants 3 messages Aug 25, 2023 – Oct 4, 2023

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

PATCH 1/1 can: raw: Remove NULL check before dev_{put, hold}

The call netdev_{put, hold} of dev_{put, hold} will check NULL, so there is no need to check before using dev_{put, hold}, remove it to silence the warning:

./net/can/raw.c:497:2-9: WARNING: NULL check before dev_{put, hold} functions is not needed.

---
 net/can/raw.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
net/can/raw.c +1 -2
index d50c3f3d892f..ff7797c37018 100644
@@ -493,8 +493,7 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len)
 
 out_put_dev:
 	/* remove potential reference from dev_get_by_index() */
-	if (dev)
-		dev_put(dev);
+	dev_put(dev);
 out:
 	release_sock(sk);
 	rtnl_unlock();
Signature · 1 line
2.20.1.7.g153144c
maintainer Acked-by on v1 1/1
#1 lore raw

No need to hurry!

This improvement has already been reported by Simon Horman, see this discussion:

https://lore.kernel.org/linux-can/[email protected]/

@Marc Kleine-Budde: Can you please take this patch via can-next tree?

Thanks,
Oliver

Quoted 27 lines · Jiapeng Chong

The call netdev_{put, hold} of dev_{put, hold} will check NULL, so there is no need to check before using dev_{put, hold}, remove it to silence the warning:

./net/can/raw.c:497:2-9: WARNING: NULL check before dev_{put, hold} functions is not needed.

---
  net/can/raw.c | 3 +--
  1 file changed, 1 insertion(+), 2 deletions(-)
net/can/raw.c +1 -2
index d50c3f3d892f..ff7797c37018 100644
@@ -493,8 +493,7 @@ static int raw_bind(struct socket *sock, struct sockaddr *uaddr, int len)
 
  out_put_dev:
  	/* remove potential reference from dev_get_by_index() */
-	if (dev)
-		dev_put(dev);
+	dev_put(dev);
  out:
  	release_sock(sk);
  	rtnl_unlock();
#2 lore raw
In reply to Jiapeng Chong
Quoted 9 lines · Jiapeng Chong

The call netdev_{put, hold} of dev_{put, hold} will check NULL, so there is no need to check before using dev_{put, hold}, remove it to silence the warning:

./net/can/raw.c:497:2-9: WARNING: NULL check before dev_{put, hold} functions is not needed.

Applied to linux-can-next/testing.

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung Nürnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |