public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] can: usb: f81604: handle short interrupt urb messages properly
@ 2026-02-23 12:10 Greg Kroah-Hartman
  2026-02-23 12:10 ` [PATCH 2/3] can: usb: f81604: handle bulk write errors properly Greg Kroah-Hartman
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-02-23 12:10 UTC (permalink / raw)
  To: linux-can
  Cc: linux-kernel, Greg Kroah-Hartman, Ji-Ze Hong (Peter Hong),
	Marc Kleine-Budde, Vincent Mailhol, stable

If an interrupt urb is recieved that is not the correct length, properly
detect it and don't attempt to treat the data as valid.

Cc: "Ji-Ze Hong (Peter Hong)" <peter_hong@fintek.com.tw>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Vincent Mailhol <mailhol@kernel.org>
Cc: stable <stable@kernel.org>
Assisted-by: gkh_clanker_2000
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/net/can/usb/f81604.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/net/can/usb/f81604.c b/drivers/net/can/usb/f81604.c
index 76578063ac82..c61bd30d1765 100644
--- a/drivers/net/can/usb/f81604.c
+++ b/drivers/net/can/usb/f81604.c
@@ -620,6 +620,12 @@ static void f81604_read_int_callback(struct urb *urb)
 		netdev_info(netdev, "%s: Int URB aborted: %pe\n", __func__,
 			    ERR_PTR(urb->status));
 
+	if (urb->actual_length < sizeof(*data)) {
+		netdev_warn(netdev, "%s: short int URB: %u < %zu\n",
+			    __func__, urb->actual_length, sizeof(*data));
+		goto resubmit_urb;
+	}
+
 	switch (urb->status) {
 	case 0: /* success */
 		break;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] can: usb: f81604: handle bulk write errors properly
  2026-02-23 12:10 [PATCH 1/3] can: usb: f81604: handle short interrupt urb messages properly Greg Kroah-Hartman
@ 2026-02-23 12:10 ` Greg Kroah-Hartman
  2026-02-23 12:10 ` [PATCH 3/3] can: usb: f81604: correctly anchor the urb in the read bulk callback Greg Kroah-Hartman
  2026-03-02 10:08 ` [PATCH 1/3] can: usb: f81604: handle short interrupt urb messages properly Marc Kleine-Budde
  2 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-02-23 12:10 UTC (permalink / raw)
  To: linux-can
  Cc: linux-kernel, Greg Kroah-Hartman, Ji-Ze Hong (Peter Hong),
	Marc Kleine-Budde, Vincent Mailhol, stable

If a write urb fails then more needs to be done other than just logging
the message, otherwise the transmission could be stalled.  Properly
increment the error counters and wake up the queues so that data will
continue to flow.

Cc: "Ji-Ze Hong (Peter Hong)" <peter_hong@fintek.com.tw>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Vincent Mailhol <mailhol@kernel.org>
Cc: stable <stable@kernel.org>
Assisted-by: gkh_clanker_2000
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/net/can/usb/f81604.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/f81604.c b/drivers/net/can/usb/f81604.c
index c61bd30d1765..a41c6fef2a94 100644
--- a/drivers/net/can/usb/f81604.c
+++ b/drivers/net/can/usb/f81604.c
@@ -880,9 +880,27 @@ static void f81604_write_bulk_callback(struct urb *urb)
 	if (!netif_device_present(netdev))
 		return;
 
-	if (urb->status)
-		netdev_info(netdev, "%s: Tx URB error: %pe\n", __func__,
+	if (!urb->status)
+		return;
+
+	switch (urb->status) {
+	case -ENOENT:
+	case -ECONNRESET:
+	case -ESHUTDOWN:
+		return;
+	default:
+		break;
+	}
+
+	if (net_ratelimit())
+		netdev_err(netdev, "%s: Tx URB error: %pe\n", __func__,
 			    ERR_PTR(urb->status));
+
+	can_free_echo_skb(netdev, 0, NULL);
+	netdev->stats.tx_dropped++;
+	netdev->stats.tx_errors++;
+
+	netif_wake_queue(netdev);
 }
 
 static void f81604_clear_reg_work(struct work_struct *work)
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] can: usb: f81604: correctly anchor the urb in the read bulk callback
  2026-02-23 12:10 [PATCH 1/3] can: usb: f81604: handle short interrupt urb messages properly Greg Kroah-Hartman
  2026-02-23 12:10 ` [PATCH 2/3] can: usb: f81604: handle bulk write errors properly Greg Kroah-Hartman
@ 2026-02-23 12:10 ` Greg Kroah-Hartman
  2026-03-02 10:08 ` [PATCH 1/3] can: usb: f81604: handle short interrupt urb messages properly Marc Kleine-Budde
  2 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-02-23 12:10 UTC (permalink / raw)
  To: linux-can
  Cc: linux-kernel, Greg Kroah-Hartman, Ji-Ze Hong (Peter Hong),
	Marc Kleine-Budde, Vincent Mailhol, stable

When submitting an urb, that is using the anchor pattern, it needs to be
anchored before submitting it otherwise it could be leaked if
usb_kill_anchored_urbs() is called.  This logic is correctly done
elsewhere in the driver, except in the read bulk callback so do that
here also.

Cc: "Ji-Ze Hong (Peter Hong)" <peter_hong@fintek.com.tw>
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: Vincent Mailhol <mailhol@kernel.org>
Cc: stable <stable@kernel.org>
Assisted-by: gkh_clanker_2000
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/net/can/usb/f81604.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/usb/f81604.c b/drivers/net/can/usb/f81604.c
index a41c6fef2a94..68a6ef113843 100644
--- a/drivers/net/can/usb/f81604.c
+++ b/drivers/net/can/usb/f81604.c
@@ -413,6 +413,7 @@ static void f81604_read_bulk_callback(struct urb *urb)
 {
 	struct f81604_can_frame *frame = urb->transfer_buffer;
 	struct net_device *netdev = urb->context;
+	struct f81604_port_priv *priv = netdev_priv(netdev);
 	int ret;
 
 	if (!netif_device_present(netdev))
@@ -445,10 +446,15 @@ static void f81604_read_bulk_callback(struct urb *urb)
 	f81604_process_rx_packet(netdev, frame);
 
 resubmit_urb:
+	usb_anchor_urb(urb, &priv->urbs_anchor);
 	ret = usb_submit_urb(urb, GFP_ATOMIC);
+	if (!ret)
+		return;
+	usb_unanchor_urb(urb);
+
 	if (ret == -ENODEV)
 		netif_device_detach(netdev);
-	else if (ret)
+	else
 		netdev_err(netdev,
 			   "%s: failed to resubmit read bulk urb: %pe\n",
 			   __func__, ERR_PTR(ret));
@@ -652,10 +658,15 @@ static void f81604_read_int_callback(struct urb *urb)
 		f81604_handle_tx(priv, data);
 
 resubmit_urb:
+	usb_anchor_urb(urb, &priv->urbs_anchor);
 	ret = usb_submit_urb(urb, GFP_ATOMIC);
+	if (!ret)
+		return;
+	usb_unanchor_urb(urb);
+
 	if (ret == -ENODEV)
 		netif_device_detach(netdev);
-	else if (ret)
+	else
 		netdev_err(netdev, "%s: failed to resubmit int urb: %pe\n",
 			   __func__, ERR_PTR(ret));
 }
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] can: usb: f81604: handle short interrupt urb messages properly
  2026-02-23 12:10 [PATCH 1/3] can: usb: f81604: handle short interrupt urb messages properly Greg Kroah-Hartman
  2026-02-23 12:10 ` [PATCH 2/3] can: usb: f81604: handle bulk write errors properly Greg Kroah-Hartman
  2026-02-23 12:10 ` [PATCH 3/3] can: usb: f81604: correctly anchor the urb in the read bulk callback Greg Kroah-Hartman
@ 2026-03-02 10:08 ` Marc Kleine-Budde
  2026-03-02 12:50   ` Greg Kroah-Hartman
  2 siblings, 1 reply; 5+ messages in thread
From: Marc Kleine-Budde @ 2026-03-02 10:08 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: linux-can, linux-kernel, Ji-Ze Hong (Peter Hong), Vincent Mailhol,
	stable

[-- Attachment #1: Type: text/plain, Size: 872 bytes --]

On 23.02.2026 13:10:30, Greg Kroah-Hartman wrote:
> If an interrupt urb is recieved that is not the correct length, properly
                            ^^
> detect it and don't attempt to treat the data as valid.
>
> Cc: "Ji-Ze Hong (Peter Hong)" <peter_hong@fintek.com.tw>
> Cc: Marc Kleine-Budde <mkl@pengutronix.de>
> Cc: Vincent Mailhol <mailhol@kernel.org>
> Cc: stable <stable@kernel.org>
> Assisted-by: gkh_clanker_2000
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Applied whole series to linux-can, with typo fix and preferred stable
format.

regards,
Marc

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/3] can: usb: f81604: handle short interrupt urb messages properly
  2026-03-02 10:08 ` [PATCH 1/3] can: usb: f81604: handle short interrupt urb messages properly Marc Kleine-Budde
@ 2026-03-02 12:50   ` Greg Kroah-Hartman
  0 siblings, 0 replies; 5+ messages in thread
From: Greg Kroah-Hartman @ 2026-03-02 12:50 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: linux-can, linux-kernel, Ji-Ze Hong (Peter Hong), Vincent Mailhol,
	stable

On Mon, Mar 02, 2026 at 11:08:21AM +0100, Marc Kleine-Budde wrote:
> On 23.02.2026 13:10:30, Greg Kroah-Hartman wrote:
> > If an interrupt urb is recieved that is not the correct length, properly
>                             ^^
> > detect it and don't attempt to treat the data as valid.
> >
> > Cc: "Ji-Ze Hong (Peter Hong)" <peter_hong@fintek.com.tw>
> > Cc: Marc Kleine-Budde <mkl@pengutronix.de>
> > Cc: Vincent Mailhol <mailhol@kernel.org>
> > Cc: stable <stable@kernel.org>
> > Assisted-by: gkh_clanker_2000
> > Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> 
> Applied whole series to linux-can, with typo fix and preferred stable
> format.

Thanks!

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-02 12:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-23 12:10 [PATCH 1/3] can: usb: f81604: handle short interrupt urb messages properly Greg Kroah-Hartman
2026-02-23 12:10 ` [PATCH 2/3] can: usb: f81604: handle bulk write errors properly Greg Kroah-Hartman
2026-02-23 12:10 ` [PATCH 3/3] can: usb: f81604: correctly anchor the urb in the read bulk callback Greg Kroah-Hartman
2026-03-02 10:08 ` [PATCH 1/3] can: usb: f81604: handle short interrupt urb messages properly Marc Kleine-Budde
2026-03-02 12:50   ` Greg Kroah-Hartman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox