can: usb: f81604: handle short interrupt urb messages properly
PATCH 1/3 can: usb: f81604: handle short interrupt urb messages properly
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.
--- drivers/net/can/usb/f81604.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/net/can/usb/f81604.c +6 -0
@@ -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 ;
Signature · 1 line
2.53.0
PATCH 2/3 can: usb: f81604: handle bulk write errors properly
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.
--- drivers/net/can/usb/f81604.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
drivers/net/can/usb/f81604.c +20 -2
@@ -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)
Signature · 1 line
2.53.0
PATCH 3/3 can: usb: f81604: correctly anchor the urb in the read bulk callback
In reply to Greg Kroah-HartmanWhen 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.
--- drivers/net/can/usb/f81604.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/can/usb/f81604.c +13 -2
@@ -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)); }
Signature · 1 line
2.53.0
Marc Kleine-Budde
maintainerQuoted 1 line · Greg Kroah-Hartman
If an interrupt urb is recieved that is not the correct length, properly
^^
Quoted 8 lines
detect it and don't attempt to treat the data as valid.
Cc "Ji-Ze Hong (Peter Hong)" <[email protected]>Cc Marc Kleine-Budde <[email protected]>Cc Vincent Mailhol <[email protected]>Cc stable <[email protected]>Assisted-by gkh_clanker_2000Signed-off-by Greg Kroah-Hartman <[email protected]>
Applied whole series to linux-can, with typo fix and preferred stable format.
regards,
Marc
Signature · 4 lines
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 |
Quoted 12 lines · Marc Kleine-Budde
Quoted 1 line · Greg Kroah-Hartman
If an interrupt urb is recieved that is not the correct length, properly
^^Quoted 8 lines
detect it and don't attempt to treat the data as valid.
Cc "Ji-Ze Hong (Peter Hong)" <[email protected]>Cc Marc Kleine-Budde <[email protected]>Cc Vincent Mailhol <[email protected]>Cc stable <[email protected]>Assisted-by gkh_clanker_2000Signed-off-by Greg Kroah-Hartman <[email protected]>
Quoted 2 lines
Applied whole series to linux-can, with typo fix and preferred stable format.
Thanks!