From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from metis.whiteo.stw.pengutronix.de (metis.whiteo.stw.pengutronix.de [185.203.201.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38ACA344046 for ; Fri, 21 Nov 2025 10:31:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.203.201.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763721109; cv=none; b=WSdbNGdDVXAzQO/fxxJvtvdP22QzYDziV0bwazeWfh4Fp7Ju7k1VtYChT/9Co9Y/FBfENrtGEW5p9EZDAWZ9Fc1EEcrQQMV5QpbGReG+FalkTWiU+rnAgwH67ess6K98Pip6zSU3ejlJcDn+dnbQdPc9e1woaR4FPS8DZnE91D8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763721109; c=relaxed/simple; bh=B5mfb2zaAk3LMqKxrNUGJP4r1cOMlgb3FezWa/xTTv0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ReLdkkYlEJEZP6LSsluSLFGvha+CpcCJ3C5rf0/JhUbPpjKklPO6sl9l65aS8jG5uzxadPIzygMMNSeCT20p52mNQIJqBOfnPzm7xJKkeCHGgzV2MujgJXqw8LYMykGDhjVrrRbJDZPdEEWdPeaap2bSf9pEM6kZSsjpa6PUs0o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de; spf=pass smtp.mailfrom=pengutronix.de; arc=none smtp.client-ip=185.203.201.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pengutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pengutronix.de Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.whiteo.stw.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1vMOQR-0002xX-ST; Fri, 21 Nov 2025 11:31:35 +0100 Received: from pty.whiteo.stw.pengutronix.de ([2a0a:edc0:2:b01:1d::c5]) by drehscheibe.grey.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vMOQR-001ZHY-2F; Fri, 21 Nov 2025 11:31:35 +0100 Received: from ore by pty.whiteo.stw.pengutronix.de with local (Exim 4.96) (envelope-from ) id 1vMOQR-00FsSQ-1w; Fri, 21 Nov 2025 11:31:35 +0100 Date: Fri, 21 Nov 2025 11:31:35 +0100 From: Oleksij Rempel To: Tetsuo Handa Cc: linux-can@vger.kernel.org, Network Development , Marc Kleine-Budde Subject: Re: [can/j1939] unregister_netdevice: waiting for vcan0 to become free. Usage count = 2 Message-ID: References: <3679c610-5795-4ddf-81ad-a9a043bab3fc@I-love.SAKURA.ne.jp> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-SA-Exim-Connect-IP: 2a0a:edc0:0:c01:1d::a2 X-SA-Exim-Mail-From: ore@pengutronix.de X-SA-Exim-Scanned: No (on metis.whiteo.stw.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: netdev@vger.kernel.org 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 |