🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Marc Kleine-Budde Mon, 26 Oct 2026 21:09
Re: [PATCH] can: gs_usb: kill RX URBs before destroying the netdevs
#7623
Author: Marc Kleine-Budde
Date: Mon, 26 Oct 2026 21:09
102 lines
14145 bytes
--m6udzpjeck3ay5pl
Content-Type: text/plain; protected-headers=v1; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Subject: Re: [PATCH] can: gs_usb: kill RX URBs before destroying the netdevs
MIME-Version: 1.0

On 23.09.2026 07:03:52, Fan Wu wrote:
> gs_usb_disconnect() destroys the channels one by one via
> gs_destroy_candev()/free_candev(). gs_can_close() disposes the RX bulk
> URBs on the shared parent->rx_submitted anchor only when the last
> active channel is closed. With two or more channels up, the earlier
> channels are freed while their RX URBs are still submitted, and a
> completion in gs_usb_receive_bulk_callback() accesses the freed struct
> gs_can and struct net_device.
>
> Fix this by killing the anchored RX URBs in gs_usb_disconnect() before
> the first netdev is destroyed, and in the error path of gs_usb_probe()
> before the previously created netdevs are destroyed.
>
> usb_kill_anchored_urbs() waits for running completions and a killed URB
> completes with -ENOENT, so the completion handler returns without
> resubmitting the URB. The kill in gs_can_close() of the last active
> channel then operates on an already empty anchor.
>
> This issue was found by an in-house static analysis tool.
>
> Fixes: d08e973a77d1 ("can: gs_usb: Added support for the GS_USB CAN devic=
es")
> Cc: stable@vger.kernel.org
> Co-developed-by: Song Li <songl@zju.edu.cn>
> Signed-off-by: Song Li <songl@zju.edu.cn>
> Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>
> ---
>  drivers/net/can/usb/gs_usb.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> index ec9a7cb..663746d 100644
> --- a/drivers/net/can/usb/gs_usb.c
> +++ b/drivers/net/can/usb/gs_usb.c
> @@ -1595,10 +1595,10 @@ static int gs_usb_probe(struct usb_interface *int=
f,
>
>  			/* on failure destroy previously created candevs */
>  			icount =3D i;
> +			usb_kill_anchored_urbs(&parent->rx_submitted);

I've fixed the root cause of this problem. Do not register an interface,
before all interfaces are setup:

https://lore.kernel.org/all/20261026-gs_usb-fixes-v4-2-59e3b6360053@pengutr=
onix.de/

>  			for (i =3D 0; i < icount; i++)
>  				gs_destroy_candev(parent->canch[i]);
>
> -			usb_kill_anchored_urbs(&parent->rx_submitted);
>  			kfree(parent);
>  			return rc;
>  		}
> @@ -1636,6 +1636,8 @@ static void gs_usb_disconnect(struct usb_interface =
*intf)
>  		return;
>  	}
>
> +	usb_kill_anchored_urbs(&parent->rx_submitted);
> +

The USB core disables all endpoints before calling gs_usb_disconnect(),
so this isn't needed.

>  	for (i =3D 0; i < parent->channel_cnt; i++)
>  		if (parent->canch[i])
>  			gs_destroy_candev(parent->canch[i]);
>
>
>

regards,
Marc

--=20
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung N=C3=BCrnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

--m6udzpjeck3ay5pl
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQSl+MghEFFAdY3pYJLMOmT6rpmt0gUCat/BcgAKCRDMOmT6rpmt
0noWAP9LFdKbeYotc821LjsXYFEgC5EUxEHjvy0JtAvJ14m3oQD/V7UWEUeLecq9
ReIxfAnAUjTM9paYTgJpLCIztbwfhwA=
=0wRy
-----END PGP SIGNATURE-----

--m6udzpjeck3ay5pl--
Re: [PATCH] can: gs_usb: kill RX URBs before destroying the netdevs
#7764
Author: Marc Kleine-Budde
Date: Tue, 27 Oct 2026 07:15
74 lines
13141 bytes
--ekwsdgna56i73eu4
Content-Type: text/plain; protected-headers=v1; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Subject: Re: [PATCH] can: gs_usb: kill RX URBs before destroying the netdevs
MIME-Version: 1.0

On 26.10.2026 22:09:08, Marc Kleine-Budde wrote:
> > diff --git a/drivers/net/can/usb/gs_usb.c b/drivers/net/can/usb/gs_usb.c
> > index ec9a7cb..663746d 100644
> > --- a/drivers/net/can/usb/gs_usb.c
> > +++ b/drivers/net/can/usb/gs_usb.c
> > @@ -1595,10 +1595,10 @@ static int gs_usb_probe(struct usb_interface *i=
ntf,
> >
> >  			/* on failure destroy previously created candevs */
> >  			icount =3D i;
> > +			usb_kill_anchored_urbs(&parent->rx_submitted);
>
> I've fixed the root cause of this problem. Do not register an interface,
> before all interfaces are setup:
>
> https://lore.kernel.org/all/20261026-gs_usb-fixes-v4-2-59e3b6360053@pengu=
tronix.de/
>
> >  			for (i =3D 0; i < icount; i++)
> >  				gs_destroy_candev(parent->canch[i]);
> >
> > -			usb_kill_anchored_urbs(&parent->rx_submitted);
> >  			kfree(parent);
> >  			return rc;
> >  		}
> > @@ -1636,6 +1636,8 @@ static void gs_usb_disconnect(struct usb_interfac=
e *intf)
> >  		return;
> >  	}
> >
> > +	usb_kill_anchored_urbs(&parent->rx_submitted);
> > +
>
> The USB core disables all endpoints before calling gs_usb_disconnect(),
> so this isn't needed.

This is not 100% correct. There is a small race window, that the
URB's callbacks have not completed. I'll fix this by first un-registering
the netdev and then freeing the ressources.

>
> >  	for (i =3D 0; i < parent->channel_cnt; i++)
> >  		if (parent->canch[i])
> >  			gs_destroy_candev(parent->canch[i]);

Marc

--=20
Pengutronix e.K.                 | Marc Kleine-Budde          |
Embedded Linux                   | https://www.pengutronix.de |
Vertretung N=C3=BCrnberg              | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-9   |

--ekwsdgna56i73eu4
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQSl+MghEFFAdY3pYJLMOmT6rpmt0gUCauBPnAAKCRDMOmT6rpmt
0mWfAPsFl1MLE7QpUizLHq2sq/5RnZkerQrNKXXjmgZuNMvCggEAi+gLEGr1gfS1
1YPQfzYKsEGvejWC//ZP3U2LjMPRzQQ=
=sMYZ
-----END PGP SIGNATURE-----

--ekwsdgna56i73eu4--
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads