staging: usbip: vhci: give back URBs from in-flight unlink requests

If we never received a RET_UNLINK because the TCP
connection broke the pending URBs still need to be
unlinked and given back.

Previously processes would be stuck trying to kill
the URB even after the device was detached.

Signed-off-by: Max Vozeler <max@vozeler.com>
Tested-by: Mark Wehby <MWehby@luxotticaRetail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by Max Vozeler and committed by Greg Kroah-Hartman b92a5e23 7606ee8a

+35 -7
+3
drivers/staging/usbip/vhci.h
··· 119 119 void vhci_rx_loop(struct usbip_task *ut); 120 120 void vhci_tx_loop(struct usbip_task *ut); 121 121 122 + struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, 123 + __u32 seqnum); 124 + 122 125 #define hardware (&the_controller->pdev.dev) 123 126 124 127 static inline struct vhci_device *port_to_vdev(__u32 port)
+23 -1
drivers/staging/usbip/vhci_hcd.c
··· 808 808 return 0; 809 809 } 810 810 811 - 812 811 static void vhci_device_unlink_cleanup(struct vhci_device *vdev) 813 812 { 814 813 struct vhci_unlink *unlink, *tmp; ··· 815 816 spin_lock(&vdev->priv_lock); 816 817 817 818 list_for_each_entry_safe(unlink, tmp, &vdev->unlink_tx, list) { 819 + usbip_uinfo("unlink cleanup tx %lu\n", unlink->unlink_seqnum); 818 820 list_del(&unlink->list); 819 821 kfree(unlink); 820 822 } 821 823 822 824 list_for_each_entry_safe(unlink, tmp, &vdev->unlink_rx, list) { 825 + struct urb *urb; 826 + 827 + /* give back URB of unanswered unlink request */ 828 + usbip_uinfo("unlink cleanup rx %lu\n", unlink->unlink_seqnum); 829 + 830 + urb = pickup_urb_and_free_priv(vdev, unlink->unlink_seqnum); 831 + if (!urb) { 832 + usbip_uinfo("the urb (seqnum %lu) was already given back\n", 833 + unlink->unlink_seqnum); 834 + list_del(&unlink->list); 835 + kfree(unlink); 836 + continue; 837 + } 838 + 839 + urb->status = -ENODEV; 840 + 841 + spin_lock(&the_controller->lock); 842 + usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb); 843 + spin_unlock(&the_controller->lock); 844 + 845 + usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status); 846 + 823 847 list_del(&unlink->list); 824 848 kfree(unlink); 825 849 }
+9 -6
drivers/staging/usbip/vhci_rx.c
··· 23 23 #include "vhci.h" 24 24 25 25 26 - /* get URB from transmitted urb queue */ 27 - static struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, 26 + /* get URB from transmitted urb queue. caller must hold vdev->priv_lock */ 27 + struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, 28 28 __u32 seqnum) 29 29 { 30 30 struct vhci_priv *priv, *tmp; 31 31 struct urb *urb = NULL; 32 32 int status; 33 - 34 - spin_lock(&vdev->priv_lock); 35 33 36 34 list_for_each_entry_safe(priv, tmp, &vdev->priv_rx, list) { 37 35 if (priv->seqnum == seqnum) { ··· 61 63 } 62 64 } 63 65 64 - spin_unlock(&vdev->priv_lock); 65 - 66 66 return urb; 67 67 } 68 68 ··· 70 74 struct usbip_device *ud = &vdev->ud; 71 75 struct urb *urb; 72 76 77 + spin_lock(&vdev->priv_lock); 73 78 74 79 urb = pickup_urb_and_free_priv(vdev, pdu->base.seqnum); 75 80 81 + spin_unlock(&vdev->priv_lock); 76 82 77 83 if (!urb) { 78 84 usbip_uerr("cannot find a urb of seqnum %u\n", ··· 159 161 return; 160 162 } 161 163 164 + spin_lock(&vdev->priv_lock); 165 + 162 166 urb = pickup_urb_and_free_priv(vdev, unlink->unlink_seqnum); 167 + 168 + spin_unlock(&vdev->priv_lock); 169 + 163 170 if (!urb) { 164 171 /* 165 172 * I get the result of a unlink request. But, it seems that I