From: Davide Caratti <dcaratti@redhat.com>
To: Oliver Hartkopp <socketcan@hartkopp.net>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>, linux-can@vger.kernel.org
Subject: Re: [PATCH] can: add protocol counter for AF_CAN sockets
Date: Mon, 17 Mar 2025 11:14:00 +0100 [thread overview]
Message-ID: <Z9f16MYRF_vlkkVY@dcaratti.users.ipa.redhat.com> (raw)
In-Reply-To: <78951192-82b1-45bc-9903-d314c94cd182@hartkopp.net>
thanks for reviewing!
On Sun, Mar 16, 2025 at 01:36:40PM +0100, Oliver Hartkopp wrote:
> Hello Davide,
>
> thanks for your patch!
ouch, I forgot j1939. I had a selftest for that, but I could only
test raw.
> 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?
only the last call to sock_put() needs sock_prot_inuse_add(..., -1):
[...]
> ~/linux/net/can$ git grep sock_put .
> af_can.c: sock_put(sk);
167 if (sk->sk_prot->init)
168 err = sk->sk_prot->init(sk);
169
170 if (err) {
171 /* release sk on errors */
172 sock_orphan(sk);
173 sock_put(sk);
174 sock->sk = NULL;
175 } else {
176 sock_prot_inuse_add(net, sk->sk_prot, 1);
177 }
^^ this one does not need it because the 'in_use' counter is incremented
in the else branch;
> af_can.c: sock_put(sk);
491 static void can_rx_delete_receiver(struct rcu_head *rp)
492 {
493 struct receiver *rcv = container_of(rp, struct receiver, rcu);
494 struct sock *sk = rcv->sk;
495
496 kmem_cache_free(rcv_cache, rcv);
497 if (sk)
498 sock_put(sk);
499 }
this one comes from can_rx_unregister(), and it's called in RCU callback - so
we can't tell if it happens before or after sock_put() in ->release().
So we probably need something smarter in case we are not sure that ->release()
is called at least once for each socket.
> bcm.c: sock_put(sk);
> isotp.c: sock_put(sk);
> raw.c: sock_put(sk);
this is '->release()' of each protocol, that I aimed to cover in the
patch...
> j1939/socket.c: sock_put(sk);
> j1939/transport.c: sock_put(session->sk);
... except this one, that I forgot :)
I will send a follow-up patch soon.
Thanks!
--
davide
next prev parent reply other threads:[~2025-03-17 10:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-14 11:39 [PATCH] can: add protocol counter for AF_CAN sockets Davide Caratti
2025-03-14 12:31 ` Marc Kleine-Budde
2025-03-16 12:39 ` Oliver Hartkopp
2025-03-17 9:20 ` Marc Kleine-Budde
2025-03-17 10:14 ` Oliver Hartkopp
2025-03-16 12:36 ` Oliver Hartkopp
2025-03-17 10:14 ` Davide Caratti [this message]
2025-03-17 10:21 ` Oliver Hartkopp
2025-03-17 15:50 ` Davide Caratti
2025-03-18 13:01 ` Oliver Hartkopp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z9f16MYRF_vlkkVY@dcaratti.users.ipa.redhat.com \
--to=dcaratti@redhat.com \
--cc=linux-can@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=socketcan@hartkopp.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox