aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
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
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')
-rw-r--r--drivers/usb/core/hcd.c255
-rw-r--r--drivers/usb/core/hcd.h14
-rw-r--r--drivers/usb/gadget/dummy_hcd.c22
-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
13 files changed, 420 insertions, 271 deletions
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index a5a46a55376b..a853f63b9254 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -356,11 +356,17 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
356 const u8 *bufp = tbuf; 356 const u8 *bufp = tbuf;
357 int len = 0; 357 int len = 0;
358 int patch_wakeup = 0; 358 int patch_wakeup = 0;
359 int status = 0; 359 int status;
360 int n; 360 int n;
361 361
362 might_sleep(); 362 might_sleep();
363 363
364 spin_lock_irq(&hcd_root_hub_lock);
365 status = usb_hcd_link_urb_to_ep(hcd, urb);
366 spin_unlock_irq(&hcd_root_hub_lock);
367 if (status)
368 return status;
369
364 cmd = (struct usb_ctrlrequest *) urb->setup_packet; 370 cmd = (struct usb_ctrlrequest *) urb->setup_packet;
365 typeReq = (cmd->bRequestType << 8) | cmd->bRequest; 371 typeReq = (cmd->bRequestType << 8) | cmd->bRequest;
366 wValue = le16_to_cpu (cmd->wValue); 372 wValue = le16_to_cpu (cmd->wValue);
@@ -525,10 +531,9 @@ error:
525 531
526 /* any errors get returned through the urb completion */ 532 /* any errors get returned through the urb completion */
527 spin_lock_irq(&hcd_root_hub_lock); 533 spin_lock_irq(&hcd_root_hub_lock);
528 spin_lock(&urb->lock);
529 if (urb->status == -EINPROGRESS) 534 if (urb->status == -EINPROGRESS)
530 urb->status = status; 535 urb->status = status;
531 spin_unlock(&urb->lock); 536 usb_hcd_unlink_urb_from_ep(hcd, urb);
532 537
533 /* This peculiar use of spinlocks echoes what real HC drivers do. 538 /* This peculiar use of spinlocks echoes what real HC drivers do.
534 * Avoiding calls to local_irq_disable/enable makes the code 539 * Avoiding calls to local_irq_disable/enable makes the code
@@ -571,26 +576,21 @@ void usb_hcd_poll_rh_status(struct usb_hcd *hcd)
571 spin_lock_irqsave(&hcd_root_hub_lock, flags); 576 spin_lock_irqsave(&hcd_root_hub_lock, flags);
572 urb = hcd->status_urb; 577 urb = hcd->status_urb;
573 if (urb) { 578 if (urb) {
574 spin_lock(&urb->lock); 579 hcd->poll_pending = 0;
575 if (urb->status == -EINPROGRESS) { 580 hcd->status_urb = NULL;
576 hcd->poll_pending = 0; 581 urb->status = 0;
577 hcd->status_urb = NULL; 582 urb->hcpriv = NULL;
578 urb->status = 0; 583 urb->actual_length = length;
579 urb->hcpriv = NULL; 584 memcpy(urb->transfer_buffer, buffer, length);
580 urb->actual_length = length;
581 memcpy(urb->transfer_buffer, buffer, length);
582 } else /* urb has been unlinked */
583 length = 0;
584 spin_unlock(&urb->lock);
585 585
586 usb_hcd_unlink_urb_from_ep(hcd, urb);
586 spin_unlock(&hcd_root_hub_lock); 587 spin_unlock(&hcd_root_hub_lock);
587 usb_hcd_giveback_urb(hcd, urb); 588 usb_hcd_giveback_urb(hcd, urb);
588 spin_lock(&hcd_root_hub_lock); 589 spin_lock(&hcd_root_hub_lock);
589 } else 590 } else {
590 length = 0; 591 length = 0;
591
592 if (length <= 0)
593 hcd->poll_pending = 1; 592 hcd->poll_pending = 1;
593 }
594 spin_unlock_irqrestore(&hcd_root_hub_lock, flags); 594 spin_unlock_irqrestore(&hcd_root_hub_lock, flags);
595 } 595 }
596 596
@@ -619,24 +619,26 @@ static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb)
619 int len = 1 + (urb->dev->maxchild / 8); 619 int len = 1 + (urb->dev->maxchild / 8);
620 620
621 spin_lock_irqsave (&hcd_root_hub_lock, flags); 621 spin_lock_irqsave (&hcd_root_hub_lock, flags);
622 if (urb->status != -EINPROGRESS) /* already unlinked */ 622 if (hcd->status_urb || urb->transfer_buffer_length < len) {
623 retval = urb->status;
624 else if (hcd->status_urb || urb->transfer_buffer_length < len) {
625 dev_dbg (hcd->self.controller, "not queuing rh status urb\n"); 623 dev_dbg (hcd->self.controller, "not queuing rh status urb\n");
626 retval = -EINVAL; 624 retval = -EINVAL;
627 } else { 625 goto done;
628 hcd->status_urb = urb; 626 }
629 urb->hcpriv = hcd; /* indicate it's queued */
630 627
631 if (!hcd->uses_new_polling) 628 retval = usb_hcd_link_urb_to_ep(hcd, urb);
632 mod_timer (&hcd->rh_timer, 629 if (retval)
633 (jiffies/(HZ/4) + 1) * (HZ/4)); 630 goto done;
634 631
635 /* If a status change has already occurred, report it ASAP */ 632 hcd->status_urb = urb;
636 else if (hcd->poll_pending) 633 urb->hcpriv = hcd; /* indicate it's queued */
637 mod_timer (&hcd->rh_timer, jiffies); 634 if (!hcd->uses_new_polling)
638 retval = 0; 635 mod_timer(&hcd->rh_timer, (jiffies/(HZ/4) + 1) * (HZ/4));
639 } 636
637 /* If a status change has already occurred, report it ASAP */
638 else if (hcd->poll_pending)
639 mod_timer(&hcd->rh_timer, jiffies);
640 retval = 0;
641 done:
640 spin_unlock_irqrestore (&hcd_root_hub_lock, flags); 642 spin_unlock_irqrestore (&hcd_root_hub_lock, flags);
641 return retval; 643 return retval;
642} 644}
@@ -655,11 +657,16 @@ static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb)
655/* Unlinks of root-hub control URBs are legal, but they don't do anything 657/* Unlinks of root-hub control URBs are legal, but they don't do anything
656 * since these URBs always execute synchronously. 658 * since these URBs always execute synchronously.
657 */ 659 */
658static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 660static int usb_rh_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
659{ 661{
660 unsigned long flags; 662 unsigned long flags;
663 int rc;
661 664
662 spin_lock_irqsave(&hcd_root_hub_lock, flags); 665 spin_lock_irqsave(&hcd_root_hub_lock, flags);
666 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
667 if (rc)
668 goto done;
669
663 if (usb_endpoint_num(&urb->ep->desc) == 0) { /* Control URB */ 670 if (usb_endpoint_num(&urb->ep->desc) == 0) { /* Control URB */
664 ; /* Do nothing */ 671 ; /* Do nothing */
665 672
@@ -669,14 +676,16 @@ static int usb_rh_urb_dequeue (struct usb_hcd *hcd, struct urb *urb)
669 if (urb == hcd->status_urb) { 676 if (urb == hcd->status_urb) {
670 hcd->status_urb = NULL; 677 hcd->status_urb = NULL;
671 urb->hcpriv = NULL; 678 urb->hcpriv = NULL;
679 usb_hcd_unlink_urb_from_ep(hcd, urb);
672 680
673 spin_unlock(&hcd_root_hub_lock); 681 spin_unlock(&hcd_root_hub_lock);
674 usb_hcd_giveback_urb(hcd, urb); 682 usb_hcd_giveback_urb(hcd, urb);
675 spin_lock(&hcd_root_hub_lock); 683 spin_lock(&hcd_root_hub_lock);
676 } 684 }
677 } 685 }
686 done:
678 spin_unlock_irqrestore(&hcd_root_hub_lock, flags); 687 spin_unlock_irqrestore(&hcd_root_hub_lock, flags);
679 return 0; 688 return rc;
680} 689}
681 690
682 691
@@ -977,12 +986,26 @@ EXPORT_SYMBOL (usb_calc_bus_time);
977 986
978/*-------------------------------------------------------------------------*/ 987/*-------------------------------------------------------------------------*/
979 988
980static int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb) 989/**
990 * usb_hcd_link_urb_to_ep - add an URB to its endpoint queue
991 * @hcd: host controller to which @urb was submitted
992 * @urb: URB being submitted
993 *
994 * Host controller drivers should call this routine in their enqueue()
995 * method. The HCD's private spinlock must be held and interrupts must
996 * be disabled. The actions carried out here are required for URB
997 * submission, as well as for endpoint shutdown and for usb_kill_urb.
998 *
999 * Returns 0 for no error, otherwise a negative error code (in which case
1000 * the enqueue() method must fail). If no error occurs but enqueue() fails
1001 * anyway, it must call usb_hcd_unlink_urb_from_ep() before releasing
1002 * the private spinlock and returning.
1003 */
1004int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb)
981{ 1005{
982 unsigned long flags;
983 int rc = 0; 1006 int rc = 0;
984 1007
985 spin_lock_irqsave(&hcd_urb_list_lock, flags); 1008 spin_lock(&hcd_urb_list_lock);
986 1009
987 /* Check that the URB isn't being killed */ 1010 /* Check that the URB isn't being killed */
988 if (unlikely(urb->reject)) { 1011 if (unlikely(urb->reject)) {
@@ -1009,48 +1032,48 @@ static int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb)
1009 goto done; 1032 goto done;
1010 } 1033 }
1011 done: 1034 done:
1012 spin_unlock_irqrestore(&hcd_urb_list_lock, flags); 1035 spin_unlock(&hcd_urb_list_lock);
1013 return rc; 1036 return rc;
1014} 1037}
1038EXPORT_SYMBOL_GPL(usb_hcd_link_urb_to_ep);
1015 1039
1016static int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb, 1040/**
1041 * usb_hcd_check_unlink_urb - check whether an URB may be unlinked
1042 * @hcd: host controller to which @urb was submitted
1043 * @urb: URB being checked for unlinkability
1044 * @status: error code to store in @urb if the unlink succeeds
1045 *
1046 * Host controller drivers should call this routine in their dequeue()
1047 * method. The HCD's private spinlock must be held and interrupts must
1048 * be disabled. The actions carried out here are required for making
1049 * sure than an unlink is valid.
1050 *
1051 * Returns 0 for no error, otherwise a negative error code (in which case
1052 * the dequeue() method must fail). The possible error codes are:
1053 *
1054 * -EIDRM: @urb was not submitted or has already completed.
1055 * The completion function may not have been called yet.
1056 *
1057 * -EBUSY: @urb has already been unlinked.
1058 */
1059int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,
1017 int status) 1060 int status)
1018{ 1061{
1019 unsigned long flags;
1020 struct list_head *tmp; 1062 struct list_head *tmp;
1021 int rc = 0;
1022
1023 /*
1024 * we contend for urb->status with the hcd core,
1025 * which changes it while returning the urb.
1026 *
1027 * Caller guaranteed that the urb pointer hasn't been freed, and
1028 * that it was submitted. But as a rule it can't know whether or
1029 * not it's already been unlinked ... so we respect the reversed
1030 * lock sequence needed for the usb_hcd_giveback_urb() code paths
1031 * (urb lock, then hcd_urb_list_lock) in case some other CPU is now
1032 * unlinking it.
1033 */
1034 spin_lock_irqsave(&urb->lock, flags);
1035 spin_lock(&hcd_urb_list_lock);
1036 1063
1037 /* insist the urb is still queued */ 1064 /* insist the urb is still queued */
1038 list_for_each(tmp, &urb->ep->urb_list) { 1065 list_for_each(tmp, &urb->ep->urb_list) {
1039 if (tmp == &urb->urb_list) 1066 if (tmp == &urb->urb_list)
1040 break; 1067 break;
1041 } 1068 }
1042 if (tmp != &urb->urb_list) { 1069 if (tmp != &urb->urb_list)
1043 rc = -EIDRM; 1070 return -EIDRM;
1044 goto done;
1045 }
1046 1071
1047 /* Any status except -EINPROGRESS means something already started to 1072 /* Any status except -EINPROGRESS means something already started to
1048 * unlink this URB from the hardware. So there's no more work to do. 1073 * unlink this URB from the hardware. So there's no more work to do.
1049 */ 1074 */
1050 if (urb->status != -EINPROGRESS) { 1075 if (urb->status != -EINPROGRESS)
1051 rc = -EBUSY; 1076 return -EBUSY;
1052 goto done;
1053 }
1054 urb->status = status; 1077 urb->status = status;
1055 1078
1056 /* IRQ setup can easily be broken so that USB controllers 1079 /* IRQ setup can easily be broken so that USB controllers
@@ -1065,21 +1088,28 @@ static int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,
1065 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags); 1088 set_bit(HCD_FLAG_SAW_IRQ, &hcd->flags);
1066 } 1089 }
1067 1090
1068 done: 1091 return 0;
1069 spin_unlock(&hcd_urb_list_lock);
1070 spin_unlock_irqrestore (&urb->lock, flags);
1071 return rc;
1072} 1092}
1093EXPORT_SYMBOL_GPL(usb_hcd_check_unlink_urb);
1073 1094
1074static void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb) 1095/**
1096 * usb_hcd_unlink_urb_from_ep - remove an URB from its endpoint queue
1097 * @hcd: host controller to which @urb was submitted
1098 * @urb: URB being unlinked
1099 *
1100 * Host controller drivers should call this routine before calling
1101 * usb_hcd_giveback_urb(). The HCD's private spinlock must be held and
1102 * interrupts must be disabled. The actions carried out here are required
1103 * for URB completion.
1104 */
1105void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb)
1075{ 1106{
1076 unsigned long flags;
1077
1078 /* clear all state linking urb to this dev (and hcd) */ 1107 /* clear all state linking urb to this dev (and hcd) */
1079 spin_lock_irqsave(&hcd_urb_list_lock, flags); 1108 spin_lock(&hcd_urb_list_lock);
1080 list_del_init(&urb->urb_list); 1109 list_del_init(&urb->urb_list);
1081 spin_unlock_irqrestore(&hcd_urb_list_lock, flags); 1110 spin_unlock(&hcd_urb_list_lock);
1082} 1111}
1112EXPORT_SYMBOL_GPL(usb_hcd_unlink_urb_from_ep);
1083 1113
1084static void map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb) 1114static void map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
1085{ 1115{
@@ -1153,20 +1183,15 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
1153 * URBs must be submitted in process context with interrupts 1183 * URBs must be submitted in process context with interrupts
1154 * enabled. 1184 * enabled.
1155 */ 1185 */
1156 status = usb_hcd_link_urb_to_ep(hcd, urb); 1186 map_urb_for_dma(hcd, urb);
1157 if (!status) { 1187 if (is_root_hub(urb->dev))
1158 map_urb_for_dma(hcd, urb); 1188 status = rh_urb_enqueue(hcd, urb);
1159 if (is_root_hub(urb->dev)) 1189 else
1160 status = rh_urb_enqueue(hcd, urb); 1190 status = hcd->driver->urb_enqueue(hcd, urb, mem_flags);
1161 else
1162 status = hcd->driver->urb_enqueue(hcd, urb->ep, urb,
1163 mem_flags);
1164 }
1165 1191
1166 if (unlikely(status)) { 1192 if (unlikely(status)) {
1167 usbmon_urb_submit_error(&hcd->self, urb, status); 1193 usbmon_urb_submit_error(&hcd->self, urb, status);
1168 unmap_urb_for_dma(hcd, urb); 1194 unmap_urb_for_dma(hcd, urb);
1169 usb_hcd_unlink_urb_from_ep(hcd, urb);
1170 INIT_LIST_HEAD(&urb->urb_list); 1195 INIT_LIST_HEAD(&urb->urb_list);
1171 atomic_dec(&urb->use_count); 1196 atomic_dec(&urb->use_count);
1172 if (urb->reject) 1197 if (urb->reject)
@@ -1183,24 +1208,19 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
1183 * soon as practical. we've already set up the urb's return status, 1208 * soon as practical. we've already set up the urb's return status,
1184 * but we can't know if the callback completed already. 1209 * but we can't know if the callback completed already.
1185 */ 1210 */
1186static int 1211static int unlink1(struct usb_hcd *hcd, struct urb *urb, int status)
1187unlink1 (struct usb_hcd *hcd, struct urb *urb)
1188{ 1212{
1189 int value; 1213 int value;
1190 1214
1191 if (is_root_hub(urb->dev)) 1215 if (is_root_hub(urb->dev))
1192 value = usb_rh_urb_dequeue (hcd, urb); 1216 value = usb_rh_urb_dequeue(hcd, urb, status);
1193 else { 1217 else {
1194 1218
1195 /* The only reason an HCD might fail this call is if 1219 /* The only reason an HCD might fail this call is if
1196 * it has not yet fully queued the urb to begin with. 1220 * it has not yet fully queued the urb to begin with.
1197 * Such failures should be harmless. */ 1221 * Such failures should be harmless. */
1198 value = hcd->driver->urb_dequeue (hcd, urb); 1222 value = hcd->driver->urb_dequeue(hcd, urb, status);
1199 } 1223 }
1200
1201 if (value != 0)
1202 dev_dbg (hcd->self.controller, "dequeue %p --> %d\n",
1203 urb, value);
1204 return value; 1224 return value;
1205} 1225}
1206 1226
@@ -1216,14 +1236,11 @@ int usb_hcd_unlink_urb (struct urb *urb, int status)
1216 int retval; 1236 int retval;
1217 1237
1218 hcd = bus_to_hcd(urb->dev->bus); 1238 hcd = bus_to_hcd(urb->dev->bus);
1219 1239 retval = unlink1(hcd, urb, status);
1220 retval = usb_hcd_check_unlink_urb(hcd, urb, status);
1221 if (!retval)
1222 retval = unlink1(hcd, urb);
1223 1240
1224 if (retval == 0) 1241 if (retval == 0)
1225 retval = -EINPROGRESS; 1242 retval = -EINPROGRESS;
1226 else if (retval != -EIDRM) 1243 else if (retval != -EIDRM && retval != -EBUSY)
1227 dev_dbg(&urb->dev->dev, "hcd_unlink_urb %p fail %d\n", 1244 dev_dbg(&urb->dev->dev, "hcd_unlink_urb %p fail %d\n",
1228 urb, retval); 1245 urb, retval);
1229 return retval; 1246 return retval;
@@ -1245,7 +1262,6 @@ int usb_hcd_unlink_urb (struct urb *urb, int status)
1245 */ 1262 */
1246void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb) 1263void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb)
1247{ 1264{
1248 usb_hcd_unlink_urb_from_ep(hcd, urb);
1249 unmap_urb_for_dma(hcd, urb); 1265 unmap_urb_for_dma(hcd, urb);
1250 usbmon_urb_complete (&hcd->self, urb); 1266 usbmon_urb_complete (&hcd->self, urb);
1251 usb_unanchor_urb(urb); 1267 usb_unanchor_urb(urb);
@@ -1282,7 +1298,6 @@ void usb_hcd_endpoint_disable (struct usb_device *udev,
1282rescan: 1298rescan:
1283 spin_lock_irq(&hcd_urb_list_lock); 1299 spin_lock_irq(&hcd_urb_list_lock);
1284 list_for_each_entry (urb, &ep->urb_list, urb_list) { 1300 list_for_each_entry (urb, &ep->urb_list, urb_list) {
1285 int tmp;
1286 int is_in; 1301 int is_in;
1287 1302
1288 /* the urb may already have been unlinked */ 1303 /* the urb may already have been unlinked */
@@ -1292,34 +1307,26 @@ rescan:
1292 is_in = usb_urb_dir_in(urb); 1307 is_in = usb_urb_dir_in(urb);
1293 spin_unlock(&hcd_urb_list_lock); 1308 spin_unlock(&hcd_urb_list_lock);
1294 1309
1295 spin_lock (&urb->lock); 1310 /* kick hcd */
1296 tmp = urb->status; 1311 unlink1(hcd, urb, -ESHUTDOWN);
1297 if (tmp == -EINPROGRESS) 1312 dev_dbg (hcd->self.controller,
1298 urb->status = -ESHUTDOWN; 1313 "shutdown urb %p ep%d%s%s\n",
1299 spin_unlock (&urb->lock); 1314 urb, usb_endpoint_num(&ep->desc),
1300 1315 is_in ? "in" : "out",
1301 /* kick hcd unless it's already returning this */ 1316 ({ char *s;
1302 if (tmp == -EINPROGRESS) { 1317
1303 unlink1 (hcd, urb); 1318 switch (usb_endpoint_type(&ep->desc)) {
1304 dev_dbg (hcd->self.controller, 1319 case USB_ENDPOINT_XFER_CONTROL:
1305 "shutdown urb %p ep%d%s%s\n", 1320 s = ""; break;
1306 urb, usb_endpoint_num(&ep->desc), 1321 case USB_ENDPOINT_XFER_BULK:
1307 is_in ? "in" : "out", 1322 s = "-bulk"; break;
1308 ({ char *s; 1323 case USB_ENDPOINT_XFER_INT:
1309 1324 s = "-intr"; break;
1310 switch (usb_endpoint_type(&ep->desc)) { 1325 default:
1311 case USB_ENDPOINT_XFER_CONTROL: 1326 s = "-iso"; break;
1312 s = ""; break; 1327 };
1313 case USB_ENDPOINT_XFER_BULK: 1328 s;
1314 s = "-bulk"; break; 1329 }));
1315 case USB_ENDPOINT_XFER_INT:
1316 s = "-intr"; break;
1317 default:
1318 s = "-iso"; break;
1319 };
1320 s;
1321 }));
1322 }
1323 usb_put_urb (urb); 1330 usb_put_urb (urb);
1324 1331
1325 /* list contents may have changed */ 1332 /* list contents may have changed */
diff --git a/drivers/usb/core/hcd.h b/drivers/usb/core/hcd.h
index 8683142e70e1..745be2566f62 100644
--- a/drivers/usb/core/hcd.h
+++ b/drivers/usb/core/hcd.h
@@ -189,11 +189,10 @@ struct hc_driver {
189 int (*get_frame_number) (struct usb_hcd *hcd); 189 int (*get_frame_number) (struct usb_hcd *hcd);
190 190
191 /* manage i/o requests, device state */ 191 /* manage i/o requests, device state */
192 int (*urb_enqueue) (struct usb_hcd *hcd, 192 int (*urb_enqueue)(struct usb_hcd *hcd,
193 struct usb_host_endpoint *ep, 193 struct urb *urb, gfp_t mem_flags);
194 struct urb *urb, 194 int (*urb_dequeue)(struct usb_hcd *hcd,
195 gfp_t mem_flags); 195 struct urb *urb, int status);
196 int (*urb_dequeue) (struct usb_hcd *hcd, struct urb *urb);
197 196
198 /* hw synch, freeing endpoint resources that urb_dequeue can't */ 197 /* hw synch, freeing endpoint resources that urb_dequeue can't */
199 void (*endpoint_disable)(struct usb_hcd *hcd, 198 void (*endpoint_disable)(struct usb_hcd *hcd,
@@ -211,6 +210,11 @@ struct hc_driver {
211 /* Needed only if port-change IRQs are level-triggered */ 210 /* Needed only if port-change IRQs are level-triggered */
212}; 211};
213 212
213extern int usb_hcd_link_urb_to_ep(struct usb_hcd *hcd, struct urb *urb);
214extern int usb_hcd_check_unlink_urb(struct usb_hcd *hcd, struct urb *urb,
215 int status);
216extern void usb_hcd_unlink_urb_from_ep(struct usb_hcd *hcd, struct urb *urb);
217
214extern int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags); 218extern int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags);
215extern int usb_hcd_unlink_urb (struct urb *urb, int status); 219extern int usb_hcd_unlink_urb (struct urb *urb, int status);
216extern void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb); 220extern void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb);
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index d008d1360a7a..c441d10c087e 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -962,13 +962,13 @@ static struct platform_driver dummy_udc_driver = {
962 962
963static int dummy_urb_enqueue ( 963static int dummy_urb_enqueue (
964 struct usb_hcd *hcd, 964 struct usb_hcd *hcd,
965 struct usb_host_endpoint *ep,
966 struct urb *urb, 965 struct urb *urb,
967 gfp_t mem_flags 966 gfp_t mem_flags
968) { 967) {
969 struct dummy *dum; 968 struct dummy *dum;
970 struct urbp *urbp; 969 struct urbp *urbp;
971 unsigned long flags; 970 unsigned long flags;
971 int rc;
972 972
973 if (!urb->transfer_buffer && urb->transfer_buffer_length) 973 if (!urb->transfer_buffer && urb->transfer_buffer_length)
974 return -EINVAL; 974 return -EINVAL;
@@ -980,6 +980,11 @@ static int dummy_urb_enqueue (
980 980
981 dum = hcd_to_dummy (hcd); 981 dum = hcd_to_dummy (hcd);
982 spin_lock_irqsave (&dum->lock, flags); 982 spin_lock_irqsave (&dum->lock, flags);
983 rc = usb_hcd_link_urb_to_ep(hcd, urb);
984 if (rc) {
985 kfree(urbp);
986 goto done;
987 }
983 988
984 if (!dum->udev) { 989 if (!dum->udev) {
985 dum->udev = urb->dev; 990 dum->udev = urb->dev;
@@ -997,22 +1002,28 @@ static int dummy_urb_enqueue (
997 mod_timer (&dum->timer, jiffies + 1); 1002 mod_timer (&dum->timer, jiffies + 1);
998 1003
999 spin_unlock_irqrestore (&dum->lock, flags); 1004 spin_unlock_irqrestore (&dum->lock, flags);
1000 return 0; 1005 done:
1006 return rc;
1001} 1007}
1002 1008
1003static int dummy_urb_dequeue (struct usb_hcd *hcd, struct urb *urb) 1009static int dummy_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
1004{ 1010{
1005 struct dummy *dum; 1011 struct dummy *dum;
1006 unsigned long flags; 1012 unsigned long flags;
1013 int rc;
1007 1014
1008 /* giveback happens automatically in timer callback, 1015 /* giveback happens automatically in timer callback,
1009 * so make sure the callback happens */ 1016 * so make sure the callback happens */
1010 dum = hcd_to_dummy (hcd); 1017 dum = hcd_to_dummy (hcd);
1011 spin_lock_irqsave (&dum->lock, flags); 1018 spin_lock_irqsave (&dum->lock, flags);
1012 if (dum->rh_state != DUMMY_RH_RUNNING && !list_empty(&dum->urbp_list)) 1019
1020 rc = usb_hcd_check_unlink_urb(hcd, urb, status);
1021 if (!rc && dum->rh_state != DUMMY_RH_RUNNING &&
1022 !list_empty(&dum->urbp_list))
1013 mod_timer (&dum->timer, jiffies); 1023 mod_timer (&dum->timer, jiffies);
1024
1014 spin_unlock_irqrestore (&dum->lock, flags); 1025 spin_unlock_irqrestore (&dum->lock, flags);
1015 return 0; 1026 return rc;
1016} 1027}
1017 1028
1018static void maybe_set_status (struct urb *urb, int status) 1029static void maybe_set_status (struct urb *urb, int status)
@@ -1511,6 +1522,7 @@ return_urb:
1511 if (ep) 1522 if (ep)
1512 ep->already_seen = ep->setup_stage = 0; 1523 ep->already_seen = ep->setup_stage = 0;
1513 1524
1525 usb_hcd_unlink_urb_from_ep(dummy_to_hcd(dum), urb);
1514 spin_unlock (&dum->lock); 1526 spin_unlock (&dum->lock);
1515 usb_hcd_giveback_urb (dummy_to_hcd(dum), urb); 1527 usb_hcd_giveback_urb (dummy_to_hcd(dum), urb);
1516 spin_lock (&dum->lock); 1528 spin_lock (&dum->lock);
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);