aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/host
diff options
context:
space:
mode:
authorAlan Stern <stern@rowland.harvard.edu>2007-08-08 11:48:02 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2007-10-12 17:55:10 -0400
commite9df41c5c5899259541dc928872cad4d07b82076 (patch)
tree12bb0917eeecbe62b2b5d3dc576806c7f2728550 /drivers/usb/host
parentb0e396e3097ce4914c643bc3f0c2fe0098f551eb (diff)
USB: make HCDs responsible for managing endpoint queues
This patch (as954) implements a suggestion of David Brownell's. Now the host controller drivers are responsible for linking and unlinking URBs to/from their endpoint queues. This eliminates the possiblity of strange situations where usbcore thinks an URB is linked but the HCD thinks it isn't. It also means HCDs no longer have to check for URBs being dequeued before they were fully enqueued. In addition to the core changes, this requires changing every host controller driver and the root-hub URB handler. For the most part the required changes are fairly small; drivers have to call usb_hcd_link_urb_to_ep() in their urb_enqueue method, usb_hcd_check_unlink_urb() in their urb_dequeue method, and usb_hcd_unlink_urb_from_ep() before giving URBs back. A few HCDs make matters more complicated by the way they split up the flow of control. In addition some method interfaces get changed. The endpoint argument for urb_enqueue is now redundant so it is removed. The unlink status is required by usb_hcd_check_unlink_urb(), so it has been added to urb_dequeue. Signed-off-by: Alan Stern <stern@rowland.harvard.edu> CC: David Brownell <david-b@pacbell.net> CC: Olav Kongas <ok@artecdesign.ee> CC: Tony Olech <tony.olech@elandigitalsystems.com> CC: Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/host')
-rw-r--r--drivers/usb/host/ehci-hcd.c14
-rw-r--r--drivers/usb/host/ehci-q.c14
-rw-r--r--drivers/usb/host/ehci-sched.c43
-rw-r--r--drivers/usb/host/isp116x-hcd.c31
-rw-r--r--drivers/usb/host/ohci-hcd.c32
-rw-r--r--drivers/usb/host/ohci-q.c1
-rw-r--r--drivers/usb/host/r8a66597-hcd.c37
-rw-r--r--drivers/usb/host/sl811-hcd.c26
-rw-r--r--drivers/usb/host/u132-hcd.c170
-rw-r--r--drivers/usb/host/uhci-q.c32
10 files changed, 263 insertions, 137 deletions
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index 35cdba10411b..db00492588b6 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -719,7 +719,6 @@ dead:
719 */ 719 */
720static int ehci_urb_enqueue ( 720static int ehci_urb_enqueue (
721 struct usb_hcd *hcd, 721 struct usb_hcd *hcd,
722 struct usb_host_endpoint *ep,
723 struct urb *urb, 722 struct urb *urb,
724 gfp_t mem_flags 723 gfp_t mem_flags
725) { 724) {
@@ -734,12 +733,12 @@ static int ehci_urb_enqueue (
734 default: 733 default:
735 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags)) 734 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
736 return -ENOMEM; 735 return -ENOMEM;
737 return submit_async (ehci, ep, urb, &qtd_list, mem_flags); 736 return submit_async(ehci, urb, &qtd_list, mem_flags);
738 737
739 case PIPE_INTERRUPT: 738 case PIPE_INTERRUPT:
740 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags)) 739 if (!qh_urb_transaction (ehci, urb, &qtd_list, mem_flags))
741 return -ENOMEM; 740 return -ENOMEM;
742 return intr_submit (ehci, ep, urb, &qtd_list, mem_flags); 741 return intr_submit(ehci, urb, &qtd_list, mem_flags);
743 742
744 case PIPE_ISOCHRONOUS: 743 case PIPE_ISOCHRONOUS:
745 if (urb->dev->speed == USB_SPEED_HIGH) 744 if (urb->dev->speed == USB_SPEED_HIGH)
@@ -777,13 +776,18 @@ static void unlink_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
777 * completions normally happen asynchronously 776 * completions normally happen asynchronously
778 */ 777 */
779 778
780static int ehci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 779static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
781{ 780{
782 struct ehci_hcd *ehci = hcd_to_ehci (hcd); 781 struct ehci_hcd *ehci = hcd_to_ehci (hcd);
783 struct ehci_qh *qh; 782 struct ehci_qh *qh;
784 unsigned long flags; 783 unsigned long flags;
784 int rc;
785 785
786 spin_lock_irqsave (&ehci->lock, flags); 786 spin_lock_irqsave (&ehci->lock, flags);
787 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
788 if (rc)
789 goto done;
790
787 switch (usb_pipetype (urb->pipe)) { 791 switch (usb_pipetype (urb->pipe)) {
788 // case PIPE_CONTROL: 792 // case PIPE_CONTROL:
789 // case PIPE_BULK: 793 // case PIPE_BULK:
@@ -838,7 +842,7 @@ static int ehci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
838 } 842 }
839done: 843done:
840 spin_unlock_irqrestore (&ehci->lock, flags); 844 spin_unlock_irqrestore (&ehci->lock, flags);
841 return 0; 845 return rc;
842} 846}
843 847
844/*-------------------------------------------------------------------------*/ 848/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index 140bfa423e07..1da2de4d34ed 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -262,6 +262,7 @@ __acquires(ehci->lock)
262#endif 262#endif
263 263
264 /* complete() can reenter this HCD */ 264 /* complete() can reenter this HCD */
265 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
265 spin_unlock (&ehci->lock); 266 spin_unlock (&ehci->lock);
266 usb_hcd_giveback_urb (ehci_to_hcd(ehci), urb); 267 usb_hcd_giveback_urb (ehci_to_hcd(ehci), urb);
267 spin_lock (&ehci->lock); 268 spin_lock (&ehci->lock);
@@ -913,7 +914,6 @@ static struct ehci_qh *qh_append_tds (
913static int 914static int
914submit_async ( 915submit_async (
915 struct ehci_hcd *ehci, 916 struct ehci_hcd *ehci,
916 struct usb_host_endpoint *ep,
917 struct urb *urb, 917 struct urb *urb,
918 struct list_head *qtd_list, 918 struct list_head *qtd_list,
919 gfp_t mem_flags 919 gfp_t mem_flags
@@ -922,10 +922,10 @@ submit_async (
922 int epnum; 922 int epnum;
923 unsigned long flags; 923 unsigned long flags;
924 struct ehci_qh *qh = NULL; 924 struct ehci_qh *qh = NULL;
925 int rc = 0; 925 int rc;
926 926
927 qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list); 927 qtd = list_entry (qtd_list->next, struct ehci_qtd, qtd_list);
928 epnum = ep->desc.bEndpointAddress; 928 epnum = urb->ep->desc.bEndpointAddress;
929 929
930#ifdef EHCI_URB_TRACE 930#ifdef EHCI_URB_TRACE
931 ehci_dbg (ehci, 931 ehci_dbg (ehci,
@@ -933,7 +933,7 @@ submit_async (
933 __FUNCTION__, urb->dev->devpath, urb, 933 __FUNCTION__, urb->dev->devpath, urb,
934 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out", 934 epnum & 0x0f, (epnum & USB_DIR_IN) ? "in" : "out",
935 urb->transfer_buffer_length, 935 urb->transfer_buffer_length,
936 qtd, ep->hcpriv); 936 qtd, urb->ep->hcpriv);
937#endif 937#endif
938 938
939 spin_lock_irqsave (&ehci->lock, flags); 939 spin_lock_irqsave (&ehci->lock, flags);
@@ -942,9 +942,13 @@ submit_async (
942 rc = -ESHUTDOWN; 942 rc = -ESHUTDOWN;
943 goto done; 943 goto done;
944 } 944 }
945 rc = usb_hcd_link_urb_to_ep(ehci_to_hcd(ehci), urb);
946 if (unlikely(rc))
947 goto done;
945 948
946 qh = qh_append_tds (ehci, urb, qtd_list, epnum, &ep->hcpriv); 949 qh = qh_append_tds(ehci, urb, qtd_list, epnum, &urb->ep->hcpriv);
947 if (unlikely(qh == NULL)) { 950 if (unlikely(qh == NULL)) {
951 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
948 rc = -ENOMEM; 952 rc = -ENOMEM;
949 goto done; 953 goto done;
950 } 954 }
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index e682f2342ef8..8b267b3fd2bb 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -797,7 +797,6 @@ done:
797 797
798static int intr_submit ( 798static int intr_submit (
799 struct ehci_hcd *ehci, 799 struct ehci_hcd *ehci,
800 struct usb_host_endpoint *ep,
801 struct urb *urb, 800 struct urb *urb,
802 struct list_head *qtd_list, 801 struct list_head *qtd_list,
803 gfp_t mem_flags 802 gfp_t mem_flags
@@ -805,23 +804,26 @@ static int intr_submit (
805 unsigned epnum; 804 unsigned epnum;
806 unsigned long flags; 805 unsigned long flags;
807 struct ehci_qh *qh; 806 struct ehci_qh *qh;
808 int status = 0; 807 int status;
809 struct list_head empty; 808 struct list_head empty;
810 809
811 /* get endpoint and transfer/schedule data */ 810 /* get endpoint and transfer/schedule data */
812 epnum = ep->desc.bEndpointAddress; 811 epnum = urb->ep->desc.bEndpointAddress;
813 812
814 spin_lock_irqsave (&ehci->lock, flags); 813 spin_lock_irqsave (&ehci->lock, flags);
815 814
816 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 815 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE,
817 &ehci_to_hcd(ehci)->flags))) { 816 &ehci_to_hcd(ehci)->flags))) {
818 status = -ESHUTDOWN; 817 status = -ESHUTDOWN;
819 goto done; 818 goto done_not_linked;
820 } 819 }
820 status = usb_hcd_link_urb_to_ep(ehci_to_hcd(ehci), urb);
821 if (unlikely(status))
822 goto done_not_linked;
821 823
822 /* get qh and force any scheduling errors */ 824 /* get qh and force any scheduling errors */
823 INIT_LIST_HEAD (&empty); 825 INIT_LIST_HEAD (&empty);
824 qh = qh_append_tds (ehci, urb, &empty, epnum, &ep->hcpriv); 826 qh = qh_append_tds(ehci, urb, &empty, epnum, &urb->ep->hcpriv);
825 if (qh == NULL) { 827 if (qh == NULL) {
826 status = -ENOMEM; 828 status = -ENOMEM;
827 goto done; 829 goto done;
@@ -832,13 +834,16 @@ static int intr_submit (
832 } 834 }
833 835
834 /* then queue the urb's tds to the qh */ 836 /* then queue the urb's tds to the qh */
835 qh = qh_append_tds (ehci, urb, qtd_list, epnum, &ep->hcpriv); 837 qh = qh_append_tds(ehci, urb, qtd_list, epnum, &urb->ep->hcpriv);
836 BUG_ON (qh == NULL); 838 BUG_ON (qh == NULL);
837 839
838 /* ... update usbfs periodic stats */ 840 /* ... update usbfs periodic stats */
839 ehci_to_hcd(ehci)->self.bandwidth_int_reqs++; 841 ehci_to_hcd(ehci)->self.bandwidth_int_reqs++;
840 842
841done: 843done:
844 if (unlikely(status))
845 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
846done_not_linked:
842 spin_unlock_irqrestore (&ehci->lock, flags); 847 spin_unlock_irqrestore (&ehci->lock, flags);
843 if (status) 848 if (status)
844 qtd_list_free (ehci, urb, qtd_list); 849 qtd_list_free (ehci, urb, qtd_list);
@@ -1686,12 +1691,19 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
1686 /* schedule ... need to lock */ 1691 /* schedule ... need to lock */
1687 spin_lock_irqsave (&ehci->lock, flags); 1692 spin_lock_irqsave (&ehci->lock, flags);
1688 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 1693 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE,
1689 &ehci_to_hcd(ehci)->flags))) 1694 &ehci_to_hcd(ehci)->flags))) {
1690 status = -ESHUTDOWN; 1695 status = -ESHUTDOWN;
1691 else 1696 goto done_not_linked;
1692 status = iso_stream_schedule (ehci, urb, stream); 1697 }
1698 status = usb_hcd_link_urb_to_ep(ehci_to_hcd(ehci), urb);
1699 if (unlikely(status))
1700 goto done_not_linked;
1701 status = iso_stream_schedule(ehci, urb, stream);
1693 if (likely (status == 0)) 1702 if (likely (status == 0))
1694 itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); 1703 itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
1704 else
1705 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
1706done_not_linked:
1695 spin_unlock_irqrestore (&ehci->lock, flags); 1707 spin_unlock_irqrestore (&ehci->lock, flags);
1696 1708
1697done: 1709done:
@@ -2049,12 +2061,19 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
2049 /* schedule ... need to lock */ 2061 /* schedule ... need to lock */
2050 spin_lock_irqsave (&ehci->lock, flags); 2062 spin_lock_irqsave (&ehci->lock, flags);
2051 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE, 2063 if (unlikely(!test_bit(HCD_FLAG_HW_ACCESSIBLE,
2052 &ehci_to_hcd(ehci)->flags))) 2064 &ehci_to_hcd(ehci)->flags))) {
2053 status = -ESHUTDOWN; 2065 status = -ESHUTDOWN;
2054 else 2066 goto done_not_linked;
2055 status = iso_stream_schedule (ehci, urb, stream); 2067 }
2068 status = usb_hcd_link_urb_to_ep(ehci_to_hcd(ehci), urb);
2069 if (unlikely(status))
2070 goto done_not_linked;
2071 status = iso_stream_schedule(ehci, urb, stream);
2056 if (status == 0) 2072 if (status == 0)
2057 sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream); 2073 sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
2074 else
2075 usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
2076done_not_linked:
2058 spin_unlock_irqrestore (&ehci->lock, flags); 2077 spin_unlock_irqrestore (&ehci->lock, flags);
2059 2078
2060done: 2079done:
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 5c851a36de72..d5027dc75a57 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -290,6 +290,7 @@ __releases(isp116x->lock) __acquires(isp116x->lock)
290 290
291 urb_dbg(urb, "Finish"); 291 urb_dbg(urb, "Finish");
292 292
293 usb_hcd_unlink_urb_from_ep(isp116x_to_hcd(isp116x), urb);
293 spin_unlock(&isp116x->lock); 294 spin_unlock(&isp116x->lock);
294 usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb); 295 usb_hcd_giveback_urb(isp116x_to_hcd(isp116x), urb);
295 spin_lock(&isp116x->lock); 296 spin_lock(&isp116x->lock);
@@ -673,7 +674,7 @@ static int balance(struct isp116x *isp116x, u16 period, u16 load)
673/*-----------------------------------------------------------------*/ 674/*-----------------------------------------------------------------*/
674 675
675static int isp116x_urb_enqueue(struct usb_hcd *hcd, 676static int isp116x_urb_enqueue(struct usb_hcd *hcd,
676 struct usb_host_endpoint *hep, struct urb *urb, 677 struct urb *urb,
677 gfp_t mem_flags) 678 gfp_t mem_flags)
678{ 679{
679 struct isp116x *isp116x = hcd_to_isp116x(hcd); 680 struct isp116x *isp116x = hcd_to_isp116x(hcd);
@@ -682,6 +683,7 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd,
682 int is_out = !usb_pipein(pipe); 683 int is_out = !usb_pipein(pipe);
683 int type = usb_pipetype(pipe); 684 int type = usb_pipetype(pipe);
684 int epnum = usb_pipeendpoint(pipe); 685 int epnum = usb_pipeendpoint(pipe);
686 struct usb_host_endpoint *hep = urb->ep;
685 struct isp116x_ep *ep = NULL; 687 struct isp116x_ep *ep = NULL;
686 unsigned long flags; 688 unsigned long flags;
687 int i; 689 int i;
@@ -705,7 +707,12 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd,
705 if (!HC_IS_RUNNING(hcd->state)) { 707 if (!HC_IS_RUNNING(hcd->state)) {
706 kfree(ep); 708 kfree(ep);
707 ret = -ENODEV; 709 ret = -ENODEV;
708 goto fail; 710 goto fail_not_linked;
711 }
712 ret = usb_hcd_link_urb_to_ep(hcd, urb);
713 if (ret) {
714 kfree(ep);
715 goto fail_not_linked;
709 } 716 }
710 717
711 if (hep->hcpriv) 718 if (hep->hcpriv)
@@ -818,6 +825,9 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd,
818 start_atl_transfers(isp116x); 825 start_atl_transfers(isp116x);
819 826
820 fail: 827 fail:
828 if (ret)
829 usb_hcd_unlink_urb_from_ep(hcd, urb);
830 fail_not_linked:
821 spin_unlock_irqrestore(&isp116x->lock, flags); 831 spin_unlock_irqrestore(&isp116x->lock, flags);
822 return ret; 832 return ret;
823} 833}
@@ -825,20 +835,21 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd,
825/* 835/*
826 Dequeue URBs. 836 Dequeue URBs.
827*/ 837*/
828static int isp116x_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) 838static int isp116x_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
839 int status)
829{ 840{
830 struct isp116x *isp116x = hcd_to_isp116x(hcd); 841 struct isp116x *isp116x = hcd_to_isp116x(hcd);
831 struct usb_host_endpoint *hep; 842 struct usb_host_endpoint *hep;
832 struct isp116x_ep *ep, *ep_act; 843 struct isp116x_ep *ep, *ep_act;
833 unsigned long flags; 844 unsigned long flags;
845 int rc;
834 846
835 spin_lock_irqsave(&isp116x->lock, flags); 847 spin_lock_irqsave(&isp116x->lock, flags);
848 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
849 if (rc)
850 goto done;
851
836 hep = urb->hcpriv; 852 hep = urb->hcpriv;
837 /* URB already unlinked (or never linked)? */
838 if (!hep) {
839 spin_unlock_irqrestore(&isp116x->lock, flags);
840 return 0;
841 }
842 ep = hep->hcpriv; 853 ep = hep->hcpriv;
843 WARN_ON(hep != ep->hep); 854 WARN_ON(hep != ep->hep);
844 855
@@ -856,9 +867,9 @@ static int isp116x_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
856 867
857 if (urb) 868 if (urb)
858 finish_request(isp116x, ep, urb); 869 finish_request(isp116x, ep, urb);
859 870 done:
860 spin_unlock_irqrestore(&isp116x->lock, flags); 871 spin_unlock_irqrestore(&isp116x->lock, flags);
861 return 0; 872 return rc;
862} 873}
863 874
864static void isp116x_endpoint_disable(struct usb_hcd *hcd, 875static void isp116x_endpoint_disable(struct usb_hcd *hcd,
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index d673cb9c36b1..6b06ab69938f 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -117,7 +117,6 @@ MODULE_PARM_DESC (no_handshake, "true (not default) disables BIOS handshake");
117 */ 117 */
118static int ohci_urb_enqueue ( 118static int ohci_urb_enqueue (
119 struct usb_hcd *hcd, 119 struct usb_hcd *hcd,
120 struct usb_host_endpoint *ep,
121 struct urb *urb, 120 struct urb *urb,
122 gfp_t mem_flags 121 gfp_t mem_flags
123) { 122) {
@@ -134,7 +133,7 @@ static int ohci_urb_enqueue (
134#endif 133#endif
135 134
136 /* every endpoint has a ed, locate and maybe (re)initialize it */ 135 /* every endpoint has a ed, locate and maybe (re)initialize it */
137 if (! (ed = ed_get (ohci, ep, urb->dev, pipe, urb->interval))) 136 if (! (ed = ed_get (ohci, urb->ep, urb->dev, pipe, urb->interval)))
138 return -ENOMEM; 137 return -ENOMEM;
139 138
140 /* for the private part of the URB we need the number of TDs (size) */ 139 /* for the private part of the URB we need the number of TDs (size) */
@@ -199,22 +198,17 @@ static int ohci_urb_enqueue (
199 retval = -ENODEV; 198 retval = -ENODEV;
200 goto fail; 199 goto fail;
201 } 200 }
202 201 retval = usb_hcd_link_urb_to_ep(hcd, urb);
203 /* in case of unlink-during-submit */ 202 if (retval)
204 spin_lock (&urb->lock);
205 if (urb->status != -EINPROGRESS) {
206 spin_unlock (&urb->lock);
207 urb->hcpriv = urb_priv;
208 finish_urb (ohci, urb);
209 retval = 0;
210 goto fail; 203 goto fail;
211 }
212 204
213 /* schedule the ed if needed */ 205 /* schedule the ed if needed */
214 if (ed->state == ED_IDLE) { 206 if (ed->state == ED_IDLE) {
215 retval = ed_schedule (ohci, ed); 207 retval = ed_schedule (ohci, ed);
216 if (retval < 0) 208 if (retval < 0) {
217 goto fail0; 209 usb_hcd_unlink_urb_from_ep(hcd, urb);
210 goto fail;
211 }
218 if (ed->type == PIPE_ISOCHRONOUS) { 212 if (ed->type == PIPE_ISOCHRONOUS) {
219 u16 frame = ohci_frame_no(ohci); 213 u16 frame = ohci_frame_no(ohci);
220 214
@@ -238,8 +232,6 @@ static int ohci_urb_enqueue (
238 urb->hcpriv = urb_priv; 232 urb->hcpriv = urb_priv;
239 td_submit_urb (ohci, urb); 233 td_submit_urb (ohci, urb);
240 234
241fail0:
242 spin_unlock (&urb->lock);
243fail: 235fail:
244 if (retval) 236 if (retval)
245 urb_free_priv (ohci, urb_priv); 237 urb_free_priv (ohci, urb_priv);
@@ -253,17 +245,21 @@ fail:
253 * asynchronously, and we might be dealing with an urb that's 245 * asynchronously, and we might be dealing with an urb that's
254 * partially transferred, or an ED with other urbs being unlinked. 246 * partially transferred, or an ED with other urbs being unlinked.
255 */ 247 */
256static int ohci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 248static int ohci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
257{ 249{
258 struct ohci_hcd *ohci = hcd_to_ohci (hcd); 250 struct ohci_hcd *ohci = hcd_to_ohci (hcd);
259 unsigned long flags; 251 unsigned long flags;
252 int rc;
260 253
261#ifdef OHCI_VERBOSE_DEBUG 254#ifdef OHCI_VERBOSE_DEBUG
262 urb_print (urb, "UNLINK", 1); 255 urb_print (urb, "UNLINK", 1);
263#endif 256#endif
264 257
265 spin_lock_irqsave (&ohci->lock, flags); 258 spin_lock_irqsave (&ohci->lock, flags);
266 if (HC_IS_RUNNING(hcd->state)) { 259 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
260 if (rc) {
261 ; /* Do nothing */
262 } else if (HC_IS_RUNNING(hcd->state)) {
267 urb_priv_t *urb_priv; 263 urb_priv_t *urb_priv;
268 264
269 /* Unless an IRQ completed the unlink while it was being 265 /* Unless an IRQ completed the unlink while it was being
@@ -284,7 +280,7 @@ static int ohci_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
284 finish_urb (ohci, urb); 280 finish_urb (ohci, urb);
285 } 281 }
286 spin_unlock_irqrestore (&ohci->lock, flags); 282 spin_unlock_irqrestore (&ohci->lock, flags);
287 return 0; 283 return rc;
288} 284}
289 285
290/*-------------------------------------------------------------------------*/ 286/*-------------------------------------------------------------------------*/
diff --git a/drivers/usb/host/ohci-q.c b/drivers/usb/host/ohci-q.c
index 547d39be3eb9..889c0720743b 100644
--- a/drivers/usb/host/ohci-q.c
+++ b/drivers/usb/host/ohci-q.c
@@ -74,6 +74,7 @@ __acquires(ohci->lock)
74#endif 74#endif
75 75
76 /* urb->complete() can reenter this HCD */ 76 /* urb->complete() can reenter this HCD */
77 usb_hcd_unlink_urb_from_ep(ohci_to_hcd(ohci), urb);
77 spin_unlock (&ohci->lock); 78 spin_unlock (&ohci->lock);
78 usb_hcd_giveback_urb (ohci_to_hcd(ohci), urb); 79 usb_hcd_giveback_urb (ohci_to_hcd(ohci), urb);
79 spin_lock (&ohci->lock); 80 spin_lock (&ohci->lock);
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index 40a1de4c256e..94bb229df3bc 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -784,6 +784,9 @@ static void force_dequeue(struct r8a66597 *r8a66597, u16 pipenum, u16 address)
784 if (urb) { 784 if (urb) {
785 urb->status = -ENODEV; 785 urb->status = -ENODEV;
786 urb->hcpriv = NULL; 786 urb->hcpriv = NULL;
787 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597),
788 urb);
789
787 spin_unlock(&r8a66597->lock); 790 spin_unlock(&r8a66597->lock);
788 usb_hcd_giveback_urb(r8a66597_to_hcd(r8a66597), urb); 791 usb_hcd_giveback_urb(r8a66597_to_hcd(r8a66597), urb);
789 spin_lock(&r8a66597->lock); 792 spin_lock(&r8a66597->lock);
@@ -1131,6 +1134,8 @@ static void done(struct r8a66597 *r8a66597, struct r8a66597_td *td,
1131 urb->start_frame = r8a66597_get_frame(hcd); 1134 urb->start_frame = r8a66597_get_frame(hcd);
1132 1135
1133 urb->hcpriv = NULL; 1136 urb->hcpriv = NULL;
1137 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597), urb);
1138
1134 spin_unlock(&r8a66597->lock); 1139 spin_unlock(&r8a66597->lock);
1135 usb_hcd_giveback_urb(hcd, urb); 1140 usb_hcd_giveback_urb(hcd, urb);
1136 spin_lock(&r8a66597->lock); 1141 spin_lock(&r8a66597->lock);
@@ -1722,21 +1727,25 @@ static struct r8a66597_td *r8a66597_make_td(struct r8a66597 *r8a66597,
1722} 1727}
1723 1728
1724static int r8a66597_urb_enqueue(struct usb_hcd *hcd, 1729static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
1725 struct usb_host_endpoint *hep,
1726 struct urb *urb, 1730 struct urb *urb,
1727 gfp_t mem_flags) 1731 gfp_t mem_flags)
1728{ 1732{
1733 struct usb_host_endpoint *hep = urb->ep;
1729 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); 1734 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1730 struct r8a66597_td *td = NULL; 1735 struct r8a66597_td *td = NULL;
1731 int ret = 0, request = 0; 1736 int ret, request = 0;
1732 unsigned long flags; 1737 unsigned long flags;
1733 1738
1734 spin_lock_irqsave(&r8a66597->lock, flags); 1739 spin_lock_irqsave(&r8a66597->lock, flags);
1735 if (!get_urb_to_r8a66597_dev(r8a66597, urb)) { 1740 if (!get_urb_to_r8a66597_dev(r8a66597, urb)) {
1736 ret = -ENODEV; 1741 ret = -ENODEV;
1737 goto error; 1742 goto error_not_linked;
1738 } 1743 }
1739 1744
1745 ret = usb_hcd_link_urb_to_ep(hcd, urb);
1746 if (ret)
1747 goto error_not_linked;
1748
1740 if (!hep->hcpriv) { 1749 if (!hep->hcpriv) {
1741 hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe), 1750 hep->hcpriv = kzalloc(sizeof(struct r8a66597_pipe),
1742 GFP_ATOMIC); 1751 GFP_ATOMIC);
@@ -1761,15 +1770,7 @@ static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
1761 if (list_empty(&r8a66597->pipe_queue[td->pipenum])) 1770 if (list_empty(&r8a66597->pipe_queue[td->pipenum]))
1762 request = 1; 1771 request = 1;
1763 list_add_tail(&td->queue, &r8a66597->pipe_queue[td->pipenum]); 1772 list_add_tail(&td->queue, &r8a66597->pipe_queue[td->pipenum]);
1764
1765 spin_lock(&urb->lock);
1766 if (urb->status != -EINPROGRESS) {
1767 spin_unlock(&urb->lock);
1768 ret = -EPIPE;
1769 goto error;
1770 }
1771 urb->hcpriv = td; 1773 urb->hcpriv = td;
1772 spin_unlock(&urb->lock);
1773 1774
1774 if (request) { 1775 if (request) {
1775 ret = start_transfer(r8a66597, td); 1776 ret = start_transfer(r8a66597, td);
@@ -1781,17 +1782,26 @@ static int r8a66597_urb_enqueue(struct usb_hcd *hcd,
1781 set_td_timer(r8a66597, td); 1782 set_td_timer(r8a66597, td);
1782 1783
1783error: 1784error:
1785 if (ret)
1786 usb_hcd_unlink_urb_from_ep(hcd, urb);
1787error_not_linked:
1784 spin_unlock_irqrestore(&r8a66597->lock, flags); 1788 spin_unlock_irqrestore(&r8a66597->lock, flags);
1785 return ret; 1789 return ret;
1786} 1790}
1787 1791
1788static int r8a66597_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) 1792static int r8a66597_urb_dequeue(struct usb_hcd *hcd, struct urb *urb,
1793 int status)
1789{ 1794{
1790 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd); 1795 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
1791 struct r8a66597_td *td; 1796 struct r8a66597_td *td;
1792 unsigned long flags; 1797 unsigned long flags;
1798 int rc;
1793 1799
1794 spin_lock_irqsave(&r8a66597->lock, flags); 1800 spin_lock_irqsave(&r8a66597->lock, flags);
1801 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
1802 if (rc)
1803 goto done;
1804
1795 if (urb->hcpriv) { 1805 if (urb->hcpriv) {
1796 td = urb->hcpriv; 1806 td = urb->hcpriv;
1797 pipe_stop(r8a66597, td->pipe); 1807 pipe_stop(r8a66597, td->pipe);
@@ -1799,8 +1809,9 @@ static int r8a66597_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
1799 disable_irq_empty(r8a66597, td->pipenum); 1809 disable_irq_empty(r8a66597, td->pipenum);
1800 done(r8a66597, td, td->pipenum, urb); 1810 done(r8a66597, td, td->pipenum, urb);
1801 } 1811 }
1812 done:
1802 spin_unlock_irqrestore(&r8a66597->lock, flags); 1813 spin_unlock_irqrestore(&r8a66597->lock, flags);
1803 return 0; 1814 return rc;
1804} 1815}
1805 1816
1806static void r8a66597_endpoint_disable(struct usb_hcd *hcd, 1817static void r8a66597_endpoint_disable(struct usb_hcd *hcd,
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index 4cfa3ff2c993..3d3a63d002c5 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -441,6 +441,7 @@ static void finish_request(
441 urb->hcpriv = NULL; 441 urb->hcpriv = NULL;
442 spin_unlock(&urb->lock); 442 spin_unlock(&urb->lock);
443 443
444 usb_hcd_unlink_urb_from_ep(sl811_to_hcd(sl811), urb);
444 spin_unlock(&sl811->lock); 445 spin_unlock(&sl811->lock);
445 usb_hcd_giveback_urb(sl811_to_hcd(sl811), urb); 446 usb_hcd_giveback_urb(sl811_to_hcd(sl811), urb);
446 spin_lock(&sl811->lock); 447 spin_lock(&sl811->lock);
@@ -807,7 +808,6 @@ static int balance(struct sl811 *sl811, u16 period, u16 load)
807 808
808static int sl811h_urb_enqueue( 809static int sl811h_urb_enqueue(
809 struct usb_hcd *hcd, 810 struct usb_hcd *hcd,
810 struct usb_host_endpoint *hep,
811 struct urb *urb, 811 struct urb *urb,
812 gfp_t mem_flags 812 gfp_t mem_flags
813) { 813) {
@@ -820,7 +820,8 @@ static int sl811h_urb_enqueue(
820 struct sl811h_ep *ep = NULL; 820 struct sl811h_ep *ep = NULL;
821 unsigned long flags; 821 unsigned long flags;
822 int i; 822 int i;
823 int retval = 0; 823 int retval;
824 struct usb_host_endpoint *hep = urb->ep;
824 825
825#ifdef DISABLE_ISO 826#ifdef DISABLE_ISO
826 if (type == PIPE_ISOCHRONOUS) 827 if (type == PIPE_ISOCHRONOUS)
@@ -838,7 +839,12 @@ static int sl811h_urb_enqueue(
838 || !HC_IS_RUNNING(hcd->state)) { 839 || !HC_IS_RUNNING(hcd->state)) {
839 retval = -ENODEV; 840 retval = -ENODEV;
840 kfree(ep); 841 kfree(ep);
841 goto fail; 842 goto fail_not_linked;
843 }
844 retval = usb_hcd_link_urb_to_ep(hcd, urb);
845 if (retval) {
846 kfree(ep);
847 goto fail_not_linked;
842 } 848 }
843 849
844 if (hep->hcpriv) { 850 if (hep->hcpriv) {
@@ -965,23 +971,27 @@ static int sl811h_urb_enqueue(
965 start_transfer(sl811); 971 start_transfer(sl811);
966 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable); 972 sl811_write(sl811, SL11H_IRQ_ENABLE, sl811->irq_enable);
967fail: 973fail:
974 if (retval)
975 usb_hcd_unlink_urb_from_ep(hcd, urb);
976fail_not_linked:
968 spin_unlock_irqrestore(&sl811->lock, flags); 977 spin_unlock_irqrestore(&sl811->lock, flags);
969 return retval; 978 return retval;
970} 979}
971 980
972static int sl811h_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) 981static int sl811h_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
973{ 982{
974 struct sl811 *sl811 = hcd_to_sl811(hcd); 983 struct sl811 *sl811 = hcd_to_sl811(hcd);
975 struct usb_host_endpoint *hep; 984 struct usb_host_endpoint *hep;
976 unsigned long flags; 985 unsigned long flags;
977 struct sl811h_ep *ep; 986 struct sl811h_ep *ep;
978 int retval = 0; 987 int retval;
979 988
980 spin_lock_irqsave(&sl811->lock, flags); 989 spin_lock_irqsave(&sl811->lock, flags);
981 hep = urb->hcpriv; 990 retval = usb_hcd_check_unlink_urb(hcd, urb, status);
982 if (!hep) 991 if (retval)
983 goto fail; 992 goto fail;
984 993
994 hep = urb->hcpriv;
985 ep = hep->hcpriv; 995 ep = hep->hcpriv;
986 if (ep) { 996 if (ep) {
987 /* finish right away if this urb can't be active ... 997 /* finish right away if this urb can't be active ...
@@ -1029,8 +1039,8 @@ static int sl811h_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
1029 VDBG("dequeue, urb %p active %s; wait4irq\n", urb, 1039 VDBG("dequeue, urb %p active %s; wait4irq\n", urb,
1030 (sl811->active_a == ep) ? "A" : "B"); 1040 (sl811->active_a == ep) ? "A" : "B");
1031 } else 1041 } else
1032fail:
1033 retval = -EINVAL; 1042 retval = -EINVAL;
1043 fail:
1034 spin_unlock_irqrestore(&sl811->lock, flags); 1044 spin_unlock_irqrestore(&sl811->lock, flags);
1035 return retval; 1045 return retval;
1036} 1046}
diff --git a/drivers/usb/host/u132-hcd.c b/drivers/usb/host/u132-hcd.c
index 598ad098aeeb..c87660b5edc3 100644
--- a/drivers/usb/host/u132-hcd.c
+++ b/drivers/usb/host/u132-hcd.c
@@ -521,6 +521,7 @@ static void u132_hcd_giveback_urb(struct u132 *u132, struct u132_endp *endp,
521 urb->status = status; 521 urb->status = status;
522 urb->hcpriv = NULL; 522 urb->hcpriv = NULL;
523 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 523 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
524 usb_hcd_unlink_urb_from_ep(hcd, urb);
524 endp->queue_next += 1; 525 endp->queue_next += 1;
525 if (ENDP_QUEUE_SIZE > --endp->queue_size) { 526 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
526 endp->active = 0; 527 endp->active = 0;
@@ -561,6 +562,7 @@ static void u132_hcd_abandon_urb(struct u132 *u132, struct u132_endp *endp,
561 urb->status = status; 562 urb->status = status;
562 urb->hcpriv = NULL; 563 urb->hcpriv = NULL;
563 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 564 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
565 usb_hcd_unlink_urb_from_ep(hcd, urb);
564 endp->queue_next += 1; 566 endp->queue_next += 1;
565 if (ENDP_QUEUE_SIZE > --endp->queue_size) { 567 if (ENDP_QUEUE_SIZE > --endp->queue_size) {
566 endp->active = 0; 568 endp->active = 0;
@@ -1876,20 +1878,32 @@ static int u132_hcd_reset(struct usb_hcd *hcd)
1876} 1878}
1877 1879
1878static int create_endpoint_and_queue_int(struct u132 *u132, 1880static int create_endpoint_and_queue_int(struct u132 *u132,
1879 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb, 1881 struct u132_udev *udev, struct urb *urb,
1880 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address, 1882 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1881 gfp_t mem_flags) 1883 gfp_t mem_flags)
1882{ 1884{
1883 struct u132_ring *ring; 1885 struct u132_ring *ring;
1884 unsigned long irqs; 1886 unsigned long irqs;
1885 u8 endp_number = ++u132->num_endpoints; 1887 int rc;
1886 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] = 1888 u8 endp_number;
1887 kmalloc(sizeof(struct u132_endp), mem_flags); 1889 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1890
1888 if (!endp) { 1891 if (!endp) {
1889 return -ENOMEM; 1892 return -ENOMEM;
1890 } 1893 }
1894
1895 spin_lock_init(&endp->queue_lock.slock);
1896 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1897 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
1898 if (rc) {
1899 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
1900 kfree(endp);
1901 return rc;
1902 }
1903
1904 endp_number = ++u132->num_endpoints;
1905 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
1891 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); 1906 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1892 spin_lock_init(&endp->queue_lock.slock);
1893 INIT_LIST_HEAD(&endp->urb_more); 1907 INIT_LIST_HEAD(&endp->urb_more);
1894 ring = endp->ring = &u132->ring[0]; 1908 ring = endp->ring = &u132->ring[0];
1895 if (ring->curr_endp) { 1909 if (ring->curr_endp) {
@@ -1905,7 +1919,7 @@ static int create_endpoint_and_queue_int(struct u132 *u132,
1905 endp->delayed = 0; 1919 endp->delayed = 0;
1906 endp->endp_number = endp_number; 1920 endp->endp_number = endp_number;
1907 endp->u132 = u132; 1921 endp->u132 = u132;
1908 endp->hep = hep; 1922 endp->hep = urb->ep;
1909 endp->pipetype = usb_pipetype(urb->pipe); 1923 endp->pipetype = usb_pipetype(urb->pipe);
1910 u132_endp_init_kref(u132, endp); 1924 u132_endp_init_kref(u132, endp);
1911 if (usb_pipein(urb->pipe)) { 1925 if (usb_pipein(urb->pipe)) {
@@ -1924,7 +1938,6 @@ static int create_endpoint_and_queue_int(struct u132 *u132,
1924 u132_udev_get_kref(u132, udev); 1938 u132_udev_get_kref(u132, udev);
1925 } 1939 }
1926 urb->hcpriv = u132; 1940 urb->hcpriv = u132;
1927 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1928 endp->delayed = 1; 1941 endp->delayed = 1;
1929 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval); 1942 endp->jiffies = jiffies + msecs_to_jiffies(urb->interval);
1930 endp->udev_number = address; 1943 endp->udev_number = address;
@@ -1939,8 +1952,8 @@ static int create_endpoint_and_queue_int(struct u132 *u132,
1939 return 0; 1952 return 0;
1940} 1953}
1941 1954
1942static int queue_int_on_old_endpoint(struct u132 *u132, struct u132_udev *udev, 1955static int queue_int_on_old_endpoint(struct u132 *u132,
1943 struct usb_host_endpoint *hep, struct urb *urb, 1956 struct u132_udev *udev, struct urb *urb,
1944 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, 1957 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
1945 u8 usb_endp, u8 address) 1958 u8 usb_endp, u8 address)
1946{ 1959{
@@ -1964,21 +1977,33 @@ static int queue_int_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
1964} 1977}
1965 1978
1966static int create_endpoint_and_queue_bulk(struct u132 *u132, 1979static int create_endpoint_and_queue_bulk(struct u132 *u132,
1967 struct u132_udev *udev, struct usb_host_endpoint *hep, struct urb *urb, 1980 struct u132_udev *udev, struct urb *urb,
1968 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address, 1981 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, u8 address,
1969 gfp_t mem_flags) 1982 gfp_t mem_flags)
1970{ 1983{
1971 int ring_number; 1984 int ring_number;
1972 struct u132_ring *ring; 1985 struct u132_ring *ring;
1973 unsigned long irqs; 1986 unsigned long irqs;
1974 u8 endp_number = ++u132->num_endpoints; 1987 int rc;
1975 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] = 1988 u8 endp_number;
1976 kmalloc(sizeof(struct u132_endp), mem_flags); 1989 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
1990
1977 if (!endp) { 1991 if (!endp) {
1978 return -ENOMEM; 1992 return -ENOMEM;
1979 } 1993 }
1994
1995 spin_lock_init(&endp->queue_lock.slock);
1996 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
1997 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
1998 if (rc) {
1999 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2000 kfree(endp);
2001 return rc;
2002 }
2003
2004 endp_number = ++u132->num_endpoints;
2005 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
1980 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); 2006 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
1981 spin_lock_init(&endp->queue_lock.slock);
1982 INIT_LIST_HEAD(&endp->urb_more); 2007 INIT_LIST_HEAD(&endp->urb_more);
1983 endp->dequeueing = 0; 2008 endp->dequeueing = 0;
1984 endp->edset_flush = 0; 2009 endp->edset_flush = 0;
@@ -1986,7 +2011,7 @@ static int create_endpoint_and_queue_bulk(struct u132 *u132,
1986 endp->delayed = 0; 2011 endp->delayed = 0;
1987 endp->endp_number = endp_number; 2012 endp->endp_number = endp_number;
1988 endp->u132 = u132; 2013 endp->u132 = u132;
1989 endp->hep = hep; 2014 endp->hep = urb->ep;
1990 endp->pipetype = usb_pipetype(urb->pipe); 2015 endp->pipetype = usb_pipetype(urb->pipe);
1991 u132_endp_init_kref(u132, endp); 2016 u132_endp_init_kref(u132, endp);
1992 if (usb_pipein(urb->pipe)) { 2017 if (usb_pipein(urb->pipe)) {
@@ -2015,7 +2040,6 @@ static int create_endpoint_and_queue_bulk(struct u132 *u132,
2015 } 2040 }
2016 ring->length += 1; 2041 ring->length += 1;
2017 urb->hcpriv = u132; 2042 urb->hcpriv = u132;
2018 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2019 endp->udev_number = address; 2043 endp->udev_number = address;
2020 endp->usb_addr = usb_addr; 2044 endp->usb_addr = usb_addr;
2021 endp->usb_endp = usb_endp; 2045 endp->usb_endp = usb_endp;
@@ -2029,7 +2053,7 @@ static int create_endpoint_and_queue_bulk(struct u132 *u132,
2029} 2053}
2030 2054
2031static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev, 2055static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2032 struct usb_host_endpoint *hep, struct urb *urb, 2056 struct urb *urb,
2033 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, 2057 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2034 u8 usb_endp, u8 address) 2058 u8 usb_endp, u8 address)
2035{ 2059{
@@ -2051,19 +2075,32 @@ static int queue_bulk_on_old_endpoint(struct u132 *u132, struct u132_udev *udev,
2051} 2075}
2052 2076
2053static int create_endpoint_and_queue_control(struct u132 *u132, 2077static int create_endpoint_and_queue_control(struct u132 *u132,
2054 struct usb_host_endpoint *hep, struct urb *urb, 2078 struct urb *urb,
2055 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp, 2079 struct usb_device *usb_dev, u8 usb_addr, u8 usb_endp,
2056 gfp_t mem_flags) 2080 gfp_t mem_flags)
2057{ 2081{
2058 struct u132_ring *ring; 2082 struct u132_ring *ring;
2059 u8 endp_number = ++u132->num_endpoints; 2083 unsigned long irqs;
2060 struct u132_endp *endp = hep->hcpriv = u132->endp[endp_number - 1] = 2084 int rc;
2061 kmalloc(sizeof(struct u132_endp), mem_flags); 2085 u8 endp_number;
2086 struct u132_endp *endp = kmalloc(sizeof(struct u132_endp), mem_flags);
2087
2062 if (!endp) { 2088 if (!endp) {
2063 return -ENOMEM; 2089 return -ENOMEM;
2064 } 2090 }
2091
2092 spin_lock_init(&endp->queue_lock.slock);
2093 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2094 rc = usb_hcd_link_urb_to_ep(u132_to_hcd(u132), urb);
2095 if (rc) {
2096 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2097 kfree(endp);
2098 return rc;
2099 }
2100
2101 endp_number = ++u132->num_endpoints;
2102 urb->ep->hcpriv = u132->endp[endp_number - 1] = endp;
2065 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler); 2103 INIT_DELAYED_WORK(&endp->scheduler, u132_hcd_endp_work_scheduler);
2066 spin_lock_init(&endp->queue_lock.slock);
2067 INIT_LIST_HEAD(&endp->urb_more); 2104 INIT_LIST_HEAD(&endp->urb_more);
2068 ring = endp->ring = &u132->ring[0]; 2105 ring = endp->ring = &u132->ring[0];
2069 if (ring->curr_endp) { 2106 if (ring->curr_endp) {
@@ -2079,11 +2116,10 @@ static int create_endpoint_and_queue_control(struct u132 *u132,
2079 endp->delayed = 0; 2116 endp->delayed = 0;
2080 endp->endp_number = endp_number; 2117 endp->endp_number = endp_number;
2081 endp->u132 = u132; 2118 endp->u132 = u132;
2082 endp->hep = hep; 2119 endp->hep = urb->ep;
2083 u132_endp_init_kref(u132, endp); 2120 u132_endp_init_kref(u132, endp);
2084 u132_endp_get_kref(u132, endp); 2121 u132_endp_get_kref(u132, endp);
2085 if (usb_addr == 0) { 2122 if (usb_addr == 0) {
2086 unsigned long irqs;
2087 u8 address = u132->addr[usb_addr].address; 2123 u8 address = u132->addr[usb_addr].address;
2088 struct u132_udev *udev = &u132->udev[address]; 2124 struct u132_udev *udev = &u132->udev[address];
2089 endp->udev_number = address; 2125 endp->udev_number = address;
@@ -2097,7 +2133,6 @@ static int create_endpoint_and_queue_control(struct u132 *u132,
2097 udev->endp_number_in[usb_endp] = endp_number; 2133 udev->endp_number_in[usb_endp] = endp_number;
2098 udev->endp_number_out[usb_endp] = endp_number; 2134 udev->endp_number_out[usb_endp] = endp_number;
2099 urb->hcpriv = u132; 2135 urb->hcpriv = u132;
2100 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2101 endp->queue_size = 1; 2136 endp->queue_size = 1;
2102 endp->queue_last = 0; 2137 endp->queue_last = 0;
2103 endp->queue_next = 0; 2138 endp->queue_next = 0;
@@ -2106,7 +2141,6 @@ static int create_endpoint_and_queue_control(struct u132 *u132,
2106 u132_endp_queue_work(u132, endp, 0); 2141 u132_endp_queue_work(u132, endp, 0);
2107 return 0; 2142 return 0;
2108 } else { /*(usb_addr > 0) */ 2143 } else { /*(usb_addr > 0) */
2109 unsigned long irqs;
2110 u8 address = u132->addr[usb_addr].address; 2144 u8 address = u132->addr[usb_addr].address;
2111 struct u132_udev *udev = &u132->udev[address]; 2145 struct u132_udev *udev = &u132->udev[address];
2112 endp->udev_number = address; 2146 endp->udev_number = address;
@@ -2120,7 +2154,6 @@ static int create_endpoint_and_queue_control(struct u132 *u132,
2120 udev->endp_number_in[usb_endp] = endp_number; 2154 udev->endp_number_in[usb_endp] = endp_number;
2121 udev->endp_number_out[usb_endp] = endp_number; 2155 udev->endp_number_out[usb_endp] = endp_number;
2122 urb->hcpriv = u132; 2156 urb->hcpriv = u132;
2123 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2124 endp->queue_size = 1; 2157 endp->queue_size = 1;
2125 endp->queue_last = 0; 2158 endp->queue_last = 0;
2126 endp->queue_next = 0; 2159 endp->queue_next = 0;
@@ -2132,7 +2165,7 @@ static int create_endpoint_and_queue_control(struct u132 *u132,
2132} 2165}
2133 2166
2134static int queue_control_on_old_endpoint(struct u132 *u132, 2167static int queue_control_on_old_endpoint(struct u132 *u132,
2135 struct usb_host_endpoint *hep, struct urb *urb, 2168 struct urb *urb,
2136 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr, 2169 struct usb_device *usb_dev, struct u132_endp *endp, u8 usb_addr,
2137 u8 usb_endp) 2170 u8 usb_endp)
2138{ 2171{
@@ -2232,8 +2265,8 @@ static int queue_control_on_old_endpoint(struct u132 *u132,
2232 } 2265 }
2233} 2266}
2234 2267
2235static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep, 2268static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
2236 struct urb *urb, gfp_t mem_flags) 2269 gfp_t mem_flags)
2237{ 2270{
2238 struct u132 *u132 = hcd_to_u132(hcd); 2271 struct u132 *u132 = hcd_to_u132(hcd);
2239 if (irqs_disabled()) { 2272 if (irqs_disabled()) {
@@ -2258,16 +2291,24 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2258 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) { 2291 if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT) {
2259 u8 address = u132->addr[usb_addr].address; 2292 u8 address = u132->addr[usb_addr].address;
2260 struct u132_udev *udev = &u132->udev[address]; 2293 struct u132_udev *udev = &u132->udev[address];
2261 struct u132_endp *endp = hep->hcpriv; 2294 struct u132_endp *endp = urb->ep->hcpriv;
2262 urb->actual_length = 0; 2295 urb->actual_length = 0;
2263 if (endp) { 2296 if (endp) {
2264 unsigned long irqs; 2297 unsigned long irqs;
2265 int retval; 2298 int retval;
2266 spin_lock_irqsave(&endp->queue_lock.slock, 2299 spin_lock_irqsave(&endp->queue_lock.slock,
2267 irqs); 2300 irqs);
2268 retval = queue_int_on_old_endpoint(u132, udev, 2301 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2269 hep, urb, usb_dev, endp, usb_addr, 2302 if (retval == 0) {
2270 usb_endp, address); 2303 retval = queue_int_on_old_endpoint(
2304 u132, udev, urb,
2305 usb_dev, endp,
2306 usb_addr, usb_endp,
2307 address);
2308 if (retval)
2309 usb_hcd_unlink_urb_from_ep(
2310 hcd, urb);
2311 }
2271 spin_unlock_irqrestore(&endp->queue_lock.slock, 2312 spin_unlock_irqrestore(&endp->queue_lock.slock,
2272 irqs); 2313 irqs);
2273 if (retval) { 2314 if (retval) {
@@ -2282,8 +2323,8 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2282 return -EINVAL; 2323 return -EINVAL;
2283 } else { /*(endp == NULL) */ 2324 } else { /*(endp == NULL) */
2284 return create_endpoint_and_queue_int(u132, udev, 2325 return create_endpoint_and_queue_int(u132, udev,
2285 hep, urb, usb_dev, usb_addr, usb_endp, 2326 urb, usb_dev, usb_addr,
2286 address, mem_flags); 2327 usb_endp, address, mem_flags);
2287 } 2328 }
2288 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) { 2329 } else if (usb_pipetype(urb->pipe) == PIPE_ISOCHRONOUS) {
2289 dev_err(&u132->platform_dev->dev, "the hardware does no" 2330 dev_err(&u132->platform_dev->dev, "the hardware does no"
@@ -2292,16 +2333,24 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2292 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) { 2333 } else if (usb_pipetype(urb->pipe) == PIPE_BULK) {
2293 u8 address = u132->addr[usb_addr].address; 2334 u8 address = u132->addr[usb_addr].address;
2294 struct u132_udev *udev = &u132->udev[address]; 2335 struct u132_udev *udev = &u132->udev[address];
2295 struct u132_endp *endp = hep->hcpriv; 2336 struct u132_endp *endp = urb->ep->hcpriv;
2296 urb->actual_length = 0; 2337 urb->actual_length = 0;
2297 if (endp) { 2338 if (endp) {
2298 unsigned long irqs; 2339 unsigned long irqs;
2299 int retval; 2340 int retval;
2300 spin_lock_irqsave(&endp->queue_lock.slock, 2341 spin_lock_irqsave(&endp->queue_lock.slock,
2301 irqs); 2342 irqs);
2302 retval = queue_bulk_on_old_endpoint(u132, udev, 2343 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2303 hep, urb, usb_dev, endp, usb_addr, 2344 if (retval == 0) {
2304 usb_endp, address); 2345 retval = queue_bulk_on_old_endpoint(
2346 u132, udev, urb,
2347 usb_dev, endp,
2348 usb_addr, usb_endp,
2349 address);
2350 if (retval)
2351 usb_hcd_unlink_urb_from_ep(
2352 hcd, urb);
2353 }
2305 spin_unlock_irqrestore(&endp->queue_lock.slock, 2354 spin_unlock_irqrestore(&endp->queue_lock.slock,
2306 irqs); 2355 irqs);
2307 if (retval) { 2356 if (retval) {
@@ -2314,10 +2363,10 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2314 return -EINVAL; 2363 return -EINVAL;
2315 } else 2364 } else
2316 return create_endpoint_and_queue_bulk(u132, 2365 return create_endpoint_and_queue_bulk(u132,
2317 udev, hep, urb, usb_dev, usb_addr, 2366 udev, urb, usb_dev, usb_addr,
2318 usb_endp, address, mem_flags); 2367 usb_endp, address, mem_flags);
2319 } else { 2368 } else {
2320 struct u132_endp *endp = hep->hcpriv; 2369 struct u132_endp *endp = urb->ep->hcpriv;
2321 u16 urb_size = 8; 2370 u16 urb_size = 8;
2322 u8 *b = urb->setup_packet; 2371 u8 *b = urb->setup_packet;
2323 int i = 0; 2372 int i = 0;
@@ -2340,9 +2389,16 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2340 int retval; 2389 int retval;
2341 spin_lock_irqsave(&endp->queue_lock.slock, 2390 spin_lock_irqsave(&endp->queue_lock.slock,
2342 irqs); 2391 irqs);
2343 retval = queue_control_on_old_endpoint(u132, 2392 retval = usb_hcd_link_urb_to_ep(hcd, urb);
2344 hep, urb, usb_dev, endp, usb_addr, 2393 if (retval == 0) {
2345 usb_endp); 2394 retval = queue_control_on_old_endpoint(
2395 u132, urb, usb_dev,
2396 endp, usb_addr,
2397 usb_endp);
2398 if (retval)
2399 usb_hcd_unlink_urb_from_ep(
2400 hcd, urb);
2401 }
2346 spin_unlock_irqrestore(&endp->queue_lock.slock, 2402 spin_unlock_irqrestore(&endp->queue_lock.slock,
2347 irqs); 2403 irqs);
2348 if (retval) { 2404 if (retval) {
@@ -2355,7 +2411,7 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *hep,
2355 return -EINVAL; 2411 return -EINVAL;
2356 } else 2412 } else
2357 return create_endpoint_and_queue_control(u132, 2413 return create_endpoint_and_queue_control(u132,
2358 hep, urb, usb_dev, usb_addr, usb_endp, 2414 urb, usb_dev, usb_addr, usb_endp,
2359 mem_flags); 2415 mem_flags);
2360 } 2416 }
2361 } 2417 }
@@ -2390,10 +2446,17 @@ static int dequeue_from_overflow_chain(struct u132 *u132,
2390} 2446}
2391 2447
2392static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp, 2448static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2393 struct urb *urb) 2449 struct urb *urb, int status)
2394{ 2450{
2395 unsigned long irqs; 2451 unsigned long irqs;
2452 int rc;
2453
2396 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 2454 spin_lock_irqsave(&endp->queue_lock.slock, irqs);
2455 rc = usb_hcd_check_unlink_urb(u132_to_hcd(u132), urb, status);
2456 if (rc) {
2457 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2458 return rc;
2459 }
2397 if (endp->queue_size == 0) { 2460 if (endp->queue_size == 0) {
2398 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]" 2461 dev_err(&u132->platform_dev->dev, "urb=%p not found in endp[%d]"
2399 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb, 2462 "=%p ring[%d] %c%c usb_endp=%d usb_addr=%d\n", urb,
@@ -2438,6 +2501,8 @@ static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2438 } 2501 }
2439 if (urb_slot) { 2502 if (urb_slot) {
2440 struct usb_hcd *hcd = u132_to_hcd(u132); 2503 struct usb_hcd *hcd = u132_to_hcd(u132);
2504
2505 usb_hcd_unlink_urb_from_ep(hcd, urb);
2441 endp->queue_size -= 1; 2506 endp->queue_size -= 1;
2442 if (list_empty(&endp->urb_more)) { 2507 if (list_empty(&endp->urb_more)) {
2443 spin_unlock_irqrestore(&endp->queue_lock.slock, 2508 spin_unlock_irqrestore(&endp->queue_lock.slock,
@@ -2467,7 +2532,10 @@ static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2467 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2532 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2468 return -EINVAL; 2533 return -EINVAL;
2469 } else { 2534 } else {
2470 int retval = dequeue_from_overflow_chain(u132, endp, 2535 int retval;
2536
2537 usb_hcd_unlink_urb_from_ep(u132_to_hcd(u132), urb);
2538 retval = dequeue_from_overflow_chain(u132, endp,
2471 urb); 2539 urb);
2472 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2540 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs);
2473 return retval; 2541 return retval;
@@ -2475,7 +2543,7 @@ static int u132_endp_urb_dequeue(struct u132 *u132, struct u132_endp *endp,
2475 } 2543 }
2476} 2544}
2477 2545
2478static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) 2546static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
2479{ 2547{
2480 struct u132 *u132 = hcd_to_u132(hcd); 2548 struct u132 *u132 = hcd_to_u132(hcd);
2481 if (u132->going > 2) { 2549 if (u132->going > 2) {
@@ -2490,11 +2558,11 @@ static int u132_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
2490 if (usb_pipein(urb->pipe)) { 2558 if (usb_pipein(urb->pipe)) {
2491 u8 endp_number = udev->endp_number_in[usb_endp]; 2559 u8 endp_number = udev->endp_number_in[usb_endp];
2492 struct u132_endp *endp = u132->endp[endp_number - 1]; 2560 struct u132_endp *endp = u132->endp[endp_number - 1];
2493 return u132_endp_urb_dequeue(u132, endp, urb); 2561 return u132_endp_urb_dequeue(u132, endp, urb, status);
2494 } else { 2562 } else {
2495 u8 endp_number = udev->endp_number_out[usb_endp]; 2563 u8 endp_number = udev->endp_number_out[usb_endp];
2496 struct u132_endp *endp = u132->endp[endp_number - 1]; 2564 struct u132_endp *endp = u132->endp[endp_number - 1];
2497 return u132_endp_urb_dequeue(u132, endp, urb); 2565 return u132_endp_urb_dequeue(u132, endp, urb, status);
2498 } 2566 }
2499 } 2567 }
2500} 2568}
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index 3bb908ca38e9..bff200cb3d2e 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -1376,7 +1376,6 @@ static int uhci_result_isochronous(struct uhci_hcd *uhci, struct urb *urb)
1376} 1376}
1377 1377
1378static int uhci_urb_enqueue(struct usb_hcd *hcd, 1378static int uhci_urb_enqueue(struct usb_hcd *hcd,
1379 struct usb_host_endpoint *hep,
1380 struct urb *urb, gfp_t mem_flags) 1379 struct urb *urb, gfp_t mem_flags)
1381{ 1380{
1382 int ret; 1381 int ret;
@@ -1387,19 +1386,19 @@ static int uhci_urb_enqueue(struct usb_hcd *hcd,
1387 1386
1388 spin_lock_irqsave(&uhci->lock, flags); 1387 spin_lock_irqsave(&uhci->lock, flags);
1389 1388
1390 ret = urb->status; 1389 ret = usb_hcd_link_urb_to_ep(hcd, urb);
1391 if (ret != -EINPROGRESS) /* URB already unlinked! */ 1390 if (ret)
1392 goto done; 1391 goto done_not_linked;
1393 1392
1394 ret = -ENOMEM; 1393 ret = -ENOMEM;
1395 urbp = uhci_alloc_urb_priv(uhci, urb); 1394 urbp = uhci_alloc_urb_priv(uhci, urb);
1396 if (!urbp) 1395 if (!urbp)
1397 goto done; 1396 goto done;
1398 1397
1399 if (hep->hcpriv) 1398 if (urb->ep->hcpriv)
1400 qh = (struct uhci_qh *) hep->hcpriv; 1399 qh = urb->ep->hcpriv;
1401 else { 1400 else {
1402 qh = uhci_alloc_qh(uhci, urb->dev, hep); 1401 qh = uhci_alloc_qh(uhci, urb->dev, urb->ep);
1403 if (!qh) 1402 if (!qh)
1404 goto err_no_qh; 1403 goto err_no_qh;
1405 } 1404 }
@@ -1440,27 +1439,29 @@ static int uhci_urb_enqueue(struct usb_hcd *hcd,
1440err_submit_failed: 1439err_submit_failed:
1441 if (qh->state == QH_STATE_IDLE) 1440 if (qh->state == QH_STATE_IDLE)
1442 uhci_make_qh_idle(uhci, qh); /* Reclaim unused QH */ 1441 uhci_make_qh_idle(uhci, qh); /* Reclaim unused QH */
1443
1444err_no_qh: 1442err_no_qh:
1445 uhci_free_urb_priv(uhci, urbp); 1443 uhci_free_urb_priv(uhci, urbp);
1446
1447done: 1444done:
1445 if (ret)
1446 usb_hcd_unlink_urb_from_ep(hcd, urb);
1447done_not_linked:
1448 spin_unlock_irqrestore(&uhci->lock, flags); 1448 spin_unlock_irqrestore(&uhci->lock, flags);
1449 return ret; 1449 return ret;
1450} 1450}
1451 1451
1452static int uhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb) 1452static int uhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1453{ 1453{
1454 struct uhci_hcd *uhci = hcd_to_uhci(hcd); 1454 struct uhci_hcd *uhci = hcd_to_uhci(hcd);
1455 unsigned long flags; 1455 unsigned long flags;
1456 struct urb_priv *urbp;
1457 struct uhci_qh *qh; 1456 struct uhci_qh *qh;
1457 int rc;
1458 1458
1459 spin_lock_irqsave(&uhci->lock, flags); 1459 spin_lock_irqsave(&uhci->lock, flags);
1460 urbp = urb->hcpriv; 1460 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
1461 if (!urbp) /* URB was never linked! */ 1461 if (rc)
1462 goto done; 1462 goto done;
1463 qh = urbp->qh; 1463
1464 qh = ((struct urb_priv *) urb->hcpriv)->qh;
1464 1465
1465 /* Remove Isochronous TDs from the frame list ASAP */ 1466 /* Remove Isochronous TDs from the frame list ASAP */
1466 if (qh->type == USB_ENDPOINT_XFER_ISOC) { 1467 if (qh->type == USB_ENDPOINT_XFER_ISOC) {
@@ -1477,7 +1478,7 @@ static int uhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
1477 1478
1478done: 1479done:
1479 spin_unlock_irqrestore(&uhci->lock, flags); 1480 spin_unlock_irqrestore(&uhci->lock, flags);
1480 return 0; 1481 return rc;
1481} 1482}
1482 1483
1483/* 1484/*
@@ -1529,6 +1530,7 @@ __acquires(uhci->lock)
1529 } 1530 }
1530 1531
1531 uhci_free_urb_priv(uhci, urbp); 1532 uhci_free_urb_priv(uhci, urbp);
1533 usb_hcd_unlink_urb_from_ep(uhci_to_hcd(uhci), urb);
1532 1534
1533 spin_unlock(&uhci->lock); 1535 spin_unlock(&uhci->lock);
1534 usb_hcd_giveback_urb(uhci_to_hcd(uhci), urb); 1536 usb_hcd_giveback_urb(uhci_to_hcd(uhci), urb);