Re: [PATCH] can: add protocol counter for AF_CAN sockets

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello Davide,

thanks for your patch!

~/linux/net/can$ git grep sock_put .
af_can.c:               sock_put(sk);
af_can.c:               sock_put(sk);
bcm.c:  sock_put(sk);
isotp.c:        sock_put(sk);
j1939/socket.c: sock_put(sk);
j1939/transport.c:      sock_put(session->sk);
raw.c:  sock_put(sk);

But don't we need to take care on every place where sock_put() is called where sock_prot_inuse_add() has to decrease the counter?

Best regards,
Oliver

On 14.03.25 12:39, Davide Caratti wrote:
The third column in the output of the following command:

  # grep CAN /proc/net/protocols

is systematically '0': use sock_prot_inuse_add() to account for the number
of sockets for each protocol on top of AF_CAN family.

Signed-off-by: Davide Caratti <dcaratti@xxxxxxxxxx>
---
  net/can/af_can.c | 2 ++
  net/can/bcm.c    | 1 +
  net/can/isotp.c  | 1 +
  net/can/raw.c    | 5 ++++-
  4 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/net/can/af_can.c b/net/can/af_can.c
index 01f3fbb3b67d..7b191dbe3693 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -172,6 +172,8 @@ static int can_create(struct net *net, struct socket *sock, int protocol,
  		sock_orphan(sk);
  		sock_put(sk);
  		sock->sk = NULL;
+	} else {
+		sock_prot_inuse_add(net, sk->sk_prot, 1);
  	}
errout:
diff --git a/net/can/bcm.c b/net/can/bcm.c
index 217049fa496e..6dc041e054ba 100644
--- a/net/can/bcm.c
+++ b/net/can/bcm.c
@@ -1625,6 +1625,7 @@ static int bcm_release(struct socket *sock)
  	sock->sk = NULL;
release_sock(sk);
+	sock_prot_inuse_add(net, sk->sk_prot, -1);
  	sock_put(sk);
return 0;
diff --git a/net/can/isotp.c b/net/can/isotp.c
index 16046931542a..789583c62f98 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -1239,6 +1239,7 @@ static int isotp_release(struct socket *sock)
  	sock->sk = NULL;
release_sock(sk);
+	sock_prot_inuse_add(net, sk->sk_prot, -1);
  	sock_put(sk);
return 0;
diff --git a/net/can/raw.c b/net/can/raw.c
index 9b1d5f036f57..020f21430b1d 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -397,11 +397,13 @@ static int raw_release(struct socket *sock)
  {
  	struct sock *sk = sock->sk;
  	struct raw_sock *ro;
+	struct net *net;
if (!sk)
  		return 0;
ro = raw_sk(sk);
+	net = sock_net(sk);
spin_lock(&raw_notifier_lock);
  	while (raw_busy_notifier == ro) {
@@ -421,7 +423,7 @@ static int raw_release(struct socket *sock)
  			raw_disable_allfilters(dev_net(ro->dev), ro->dev, sk);
  			netdev_put(ro->dev, &ro->dev_tracker);
  		} else {
-			raw_disable_allfilters(sock_net(sk), NULL, sk);
+			raw_disable_allfilters(net, NULL, sk);
  		}
  	}
@@ -440,6 +442,7 @@ static int raw_release(struct socket *sock)
  	release_sock(sk);
  	rtnl_unlock();
+ sock_prot_inuse_add(net, sk->sk_prot, -1);
  	sock_put(sk);
return 0;





[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux