All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksij Rempel <o.rempel@pengutronix.de>
To: Tetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
Cc: linux-can@vger.kernel.org,
	Network Development <netdev@vger.kernel.org>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Subject: Re: [can/j1939] unregister_netdevice: waiting for vcan0 to become free. Usage count = 2
Date: Fri, 21 Nov 2025 11:31:35 +0100	[thread overview]
Message-ID: <aSA_hyGuitJDHpB3@pengutronix.de> (raw)
In-Reply-To: <c95f5436-3e7e-43b8-820b-e380f059b9f8@I-love.SAKURA.ne.jp>

On Fri, Nov 21, 2025 at 07:19:24PM +0900, Tetsuo Handa wrote:
> On 2025/11/21 19:00, Oleksij Rempel wrote:
> >> Do we want to update
> >> https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/commit/net/can/j1939?id=5ac798f79b48065b0284216c7a0057271185a882
> >> in order to also try tracing refcount for j1939_session ?
> > 
> > Ack.
> > 
> 
> I see.
> 
> By the way, I am thinking
> 
> diff --git a/net/can/j1939/socket.c b/net/can/j1939/socket.c
> index 88e7160d4248..f12679446990 100644
> --- a/net/can/j1939/socket.c
> +++ b/net/can/j1939/socket.c
> @@ -477,16 +477,22 @@ static int j1939_sk_bind(struct socket *sock, struct sockaddr *uaddr, int len)
>  		struct net_device *ndev;
>  
>  		ndev = dev_get_by_index(net, addr->can_ifindex);
>  		if (!ndev) {
>  			ret = -ENODEV;
>  			goto out_release_sock;
>  		}
>  
> +		if (ndev->reg_state != NETREG_REGISTERED) {
> +			dev_put(ndev);
> +			ret = -ENODEV;
> +			goto out_release_sock;
> +		}
> +
>  		can_ml = can_get_ml_priv(ndev);
>  		if (!can_ml) {
>  			dev_put(ndev);
>  			ret = -ENODEV;
>  			goto out_release_sock;
>  		}
>  
>  		if (!(ndev->flags & IFF_UP)) {
> 
> as an alternative approach for
> https://lkml.kernel.org/r/9a3f9a95-1f58-4d67-9ab4-1ca360f86f79@I-love.SAKURA.ne.jp
> because I consider that getting a new refcount on net_device should be avoided
> when NETDEV_UNREGISTER event has already started.
> 
> Maybe we can do similar thing for j1939_session in order to avoid getting a new
> refcount on j1939_priv when NETDEV_UNREGISTER event has already started.
> 
> diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
> index fbf5c8001c9d..b22568fecba5 100644
> --- a/net/can/j1939/transport.c
> +++ b/net/can/j1939/transport.c
> @@ -1492,6 +1492,8 @@ static struct j1939_session *j1939_session_new(struct j1939_priv *priv,
>  	struct j1939_session *session;
>  	struct j1939_sk_buff_cb *skcb;
>  
> +	if (priv->ndev->reg_state != NETREG_REGISTERED)
> +		return NULL;
>  	session = kzalloc(sizeof(*session), gfp_any());
>  	if (!session)
>  		return NULL;
> 

Yes, it make sense to proactively prevent the session. Good idea.

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

  reply	other threads:[~2025-11-21 10:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-20 10:11 [can/j1939] unregister_netdevice: waiting for vcan0 to become free. Usage count = 2 Tetsuo Handa
2025-11-21  9:06 ` Oleksij Rempel
2025-11-21  9:33   ` Tetsuo Handa
2025-11-21 10:00     ` Oleksij Rempel
2025-11-21 10:19       ` Tetsuo Handa
2025-11-21 10:31         ` Oleksij Rempel [this message]
2025-11-22  7:00           ` Tetsuo Handa
2025-11-22 13:03             ` Tetsuo Handa

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=aSA_hyGuitJDHpB3@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=linux-can@vger.kernel.org \
    --cc=mkl@pengutronix.de \
    --cc=netdev@vger.kernel.org \
    --cc=penguin-kernel@i-love.sakura.ne.jp \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.