public inbox for netdev@vger.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: Robin van der Gracht <robin@protonic.nl>,
	kernel@pengutronix.de, Oliver Hartkopp <socketcan@hartkopp.net>,
	Marc Kleine-Budde <mkl@pengutronix.de>,
	linux-can@vger.kernel.org,
	Network Development <netdev@vger.kernel.org>
Subject: Re: can: j1939: unregister_netdevice: waiting for vcan0 to become free.
Date: Tue, 13 Jan 2026 15:31:59 +0100	[thread overview]
Message-ID: <aWZXX_FWwXu-ejEk@pengutronix.de> (raw)
In-Reply-To: <4b1fbe9d-5ca2-41e9-b252-1304cc7c215a@I-love.SAKURA.ne.jp>

Hi,

On Tue, Jan 13, 2026 at 12:46:30PM +0900, Tetsuo Handa wrote:
> Currently, the (session->last_cmd != 0) path in j1939_xtp_rx_rts_session_active() is
> preventing the (session->state == J1939_SESSION_WAITING_ABORT) path in j1939_tp_rxtimer()
>  from being called. This results in two j1939_priv refcounts leak (which in turn results in
> one net_device refcount leak) due to j1939_session_deactivate_activate_next() being not called.
> 
> This problem goes away if I do either
> 
> diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
> --- a/net/can/j1939/transport.c
> +++ b/net/can/j1939/transport.c
> @@ -1689,16 +1692,18 @@ static int j1939_xtp_rx_rts_session_active(struct j1939_session *session,
> 
>         if (session->last_cmd != 0) {
>                 /* we received a second rts on the same connection */
> -               netdev_alert(priv->ndev, "%s: 0x%p: connection exists (%02x %02x). last cmd: %x\n",
> +               netdev_alert(priv->ndev, "%s (modified): 0x%p: connection exists (%02x %02x). last cmd: %x\n",
>                              __func__, session, skcb->addr.sa, skcb->addr.da,
>                              session->last_cmd);
> 
> +               /*
>                 j1939_session_timers_cancel(session);
>                 j1939_session_cancel(session, J1939_XTP_ABORT_BUSY);
>                 if (session->transmission)
>                         j1939_session_deactivate_activate_next(session);
> 
>                 return -EBUSY;
> +               */
>         }
> 
>         if (session->skcb.addr.sa != skcb->addr.sa ||
> 
> or
> 
> diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
> --- a/net/can/j1939/transport.c
> +++ b/net/can/j1939/transport.c
> @@ -1697,6 +1700,11 @@ static int j1939_xtp_rx_rts_session_active(struct j1939_session *session,
>                 j1939_session_cancel(session, J1939_XTP_ABORT_BUSY);
>                 if (session->transmission)
>                         j1939_session_deactivate_activate_next(session);
> +               else if (session->state == J1939_SESSION_WAITING_ABORT) {

This way looks better for me. May be add a comment like this:
            /* Force deactivation for the receiver.
             * If we rely on the timer starting in j1939_session_cancel, 
             * a second RTS call here will cancel that timer and fail 
             * to restart it because the state is already WAITING_ABORT.
             */

> +                       netdev_alert(priv->ndev, "%s (modified): 0x%p: abort rx timeout. Force session deactivation\n",
> +                                    __func__, session);
> +                       j1939_session_deactivate_activate_next(session);
> +               }
> 
>                 return -EBUSY;
>         }
> 
> . But what is the correct approach?

The second one. Thank you for your work.

Best Regards,
Oleksij
-- 
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:[~2026-01-13 14:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-12 14:51 can: j1939: unregister_netdevice: waiting for vcan0 to become free Tetsuo Handa
2026-01-13  3:46 ` Tetsuo Handa
2026-01-13 14:31   ` Oleksij Rempel [this message]
2026-01-13 15:28     ` [PATCH] can: j1939: deactivate session upon receiving the second rts Tetsuo Handa
2026-01-14 10:17       ` Oleksij Rempel
2026-01-14 10:22       ` Marc Kleine-Budde
2026-01-14 10:27         ` Oleksij Rempel
2026-01-14 10:38       ` Marc Kleine-Budde

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=aWZXX_FWwXu-ejEk@pengutronix.de \
    --to=o.rempel@pengutronix.de \
    --cc=kernel@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 \
    --cc=robin@protonic.nl \
    --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