Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

USB: centralize -EREMOTEIO handling

This patch (as969) continues the ongoing changes to the way HCDs
report URB statuses. The programming interface has been simplified by
making usbcore responsible for clearing urb->hcpriv and for setting
-EREMOTEIO status when an URB with the URB_SHORT_NOT_OK flag ends up
as a short transfer.

By moving the work out of the HCDs, this removes a fair amount of
repeated code.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
CC: David Brownell <david-b@pacbell.net>
CC: Olav Kongas <ok@artecdesign.ee>
CC: Yoshihiro Shimoda <shimoda.yoshihiro@renesas.com>
CC: Tony Olech <tony.olech@elandigitalsystems.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Alan Stern and committed by
Greg Kroah-Hartman
b0d9efba ee7d1f3f

+18 -60
+7 -2
drivers/usb/core/hcd.c
··· 366 366 spin_unlock_irq(&hcd_root_hub_lock); 367 367 if (status) 368 368 return status; 369 + urb->hcpriv = hcd; /* Indicate it's queued */ 369 370 370 371 cmd = (struct usb_ctrlrequest *) urb->setup_packet; 371 372 typeReq = (cmd->bRequestType << 8) | cmd->bRequest; ··· 580 579 hcd->poll_pending = 0; 581 580 hcd->status_urb = NULL; 582 581 urb->status = 0; 583 - urb->hcpriv = NULL; 584 582 urb->actual_length = length; 585 583 memcpy(urb->transfer_buffer, buffer, length); 586 584 ··· 675 675 del_timer (&hcd->rh_timer); 676 676 if (urb == hcd->status_urb) { 677 677 hcd->status_urb = NULL; 678 - urb->hcpriv = NULL; 679 678 usb_hcd_unlink_urb_from_ep(hcd, urb); 680 679 681 680 spin_unlock(&hcd_root_hub_lock); ··· 1191 1192 if (unlikely(status)) { 1192 1193 usbmon_urb_submit_error(&hcd->self, urb, status); 1193 1194 unmap_urb_for_dma(hcd, urb); 1195 + urb->hcpriv = NULL; 1194 1196 INIT_LIST_HEAD(&urb->urb_list); 1195 1197 atomic_dec(&urb->use_count); 1196 1198 if (urb->reject) ··· 1265 1265 unmap_urb_for_dma(hcd, urb); 1266 1266 usbmon_urb_complete (&hcd->self, urb); 1267 1267 usb_unanchor_urb(urb); 1268 + urb->hcpriv = NULL; 1269 + if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) && 1270 + urb->actual_length < urb->transfer_buffer_length && 1271 + !urb->status)) 1272 + urb->status = -EREMOTEIO; 1268 1273 1269 1274 /* pass ownership to the completion handler */ 1270 1275 urb->complete (urb);
+2 -7
drivers/usb/gadget/dummy_hcd.c
··· 1099 1099 * 1100 1100 * partially filling a buffer optionally blocks queue advances 1101 1101 * (so completion handlers can clean up the queue) but we don't 1102 - * need to emulate such data-in-flight. so we only show part 1103 - * of the URB_SHORT_NOT_OK effect: completion status. 1102 + * need to emulate such data-in-flight. 1104 1103 */ 1105 1104 if (is_short) { 1106 1105 if (host_len == dev_len) { ··· 1110 1111 if (dev_len > host_len) 1111 1112 maybe_set_status (urb, -EOVERFLOW); 1112 1113 else 1113 - maybe_set_status (urb, 1114 - (urb->transfer_flags 1115 - & URB_SHORT_NOT_OK) 1116 - ? -EREMOTEIO : 0); 1114 + maybe_set_status (urb, 0); 1117 1115 } else if (!to_host) { 1118 1116 maybe_set_status (urb, 0); 1119 1117 if (host_len > dev_len) ··· 1512 1516 continue; 1513 1517 1514 1518 return_urb: 1515 - urb->hcpriv = NULL; 1516 1519 list_del (&urbp->urbp_list); 1517 1520 kfree (urbp); 1518 1521 if (ep)
+4 -3
drivers/usb/host/ehci-q.c
··· 232 232 } 233 233 234 234 spin_lock (&urb->lock); 235 - urb->hcpriv = NULL; 236 235 switch (urb->status) { 237 236 case -EINPROGRESS: /* success */ 238 237 urb->status = 0; ··· 394 395 /* remove it from the queue */ 395 396 spin_lock (&urb->lock); 396 397 qtd_copy_status (ehci, urb, qtd->length, token); 397 - do_status = (urb->status == -EREMOTEIO) 398 - && usb_pipecontrol (urb->pipe); 398 + if (unlikely(urb->status == -EREMOTEIO)) { 399 + do_status = usb_pipecontrol(urb->pipe); 400 + urb->status = 0; 401 + } 399 402 spin_unlock (&urb->lock); 400 403 401 404 if (stopped && qtd->qtd_list.prev != &qh->qtd_list) {
+1 -7
drivers/usb/host/isp116x-hcd.c
··· 282 282 { 283 283 unsigned i; 284 284 285 - urb->hcpriv = NULL; 286 285 ep->error_count = 0; 287 286 288 287 if (usb_pipecontrol(urb->pipe)) ··· 445 446 if (PTD_GET_ACTIVE(ptd) 446 447 || (cc != TD_CC_NOERROR && cc < 0x0E)) 447 448 break; 448 - if ((urb->transfer_flags & URB_SHORT_NOT_OK) && 449 - urb->actual_length < 450 - urb->transfer_buffer_length) 451 - status = -EREMOTEIO; 452 - else 453 - status = 0; 449 + status = 0; 454 450 ep->nextpid = 0; 455 451 break; 456 452 default:
-11
drivers/usb/host/ohci-q.c
··· 43 43 // ASSERT (urb->hcpriv != 0); 44 44 45 45 urb_free_priv (ohci, urb->hcpriv); 46 - urb->hcpriv = NULL; 47 46 48 47 spin_lock (&urb->lock); 49 48 if (likely (urb->status == -EINPROGRESS)) 50 49 urb->status = 0; 51 - /* report short control reads right even though the data TD always 52 - * has TD_R set. (much simpler, but creates the 1-td limit.) 53 - */ 54 - if (unlikely (urb->transfer_flags & URB_SHORT_NOT_OK) 55 - && unlikely (usb_pipecontrol (urb->pipe)) 56 - && urb->actual_length < urb->transfer_buffer_length 57 - && usb_pipein (urb->pipe) 58 - && urb->status == 0) { 59 - urb->status = -EREMOTEIO; 60 - } 61 50 spin_unlock (&urb->lock); 62 51 63 52 switch (usb_pipetype (urb->pipe)) {
+1 -6
drivers/usb/host/r8a66597-hcd.c
··· 783 783 784 784 if (urb) { 785 785 urb->status = -ENODEV; 786 - urb->hcpriv = NULL; 787 786 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597), 788 787 urb); 789 788 ··· 1133 1134 if (usb_pipeisoc(urb->pipe)) 1134 1135 urb->start_frame = r8a66597_get_frame(hcd); 1135 1136 1136 - urb->hcpriv = NULL; 1137 1137 usb_hcd_unlink_urb_from_ep(r8a66597_to_hcd(r8a66597), urb); 1138 1138 1139 1139 spin_unlock(&r8a66597->lock); ··· 1200 1202 td->zero_packet = 1; 1201 1203 if (rcv_len < bufsize) { 1202 1204 td->short_packet = 1; 1203 - if (urb->transfer_buffer_length != urb->actual_length && 1204 - urb->transfer_flags & URB_SHORT_NOT_OK) 1205 - status = -EREMOTEIO; 1206 1205 } 1207 1206 if (usb_pipeisoc(urb->pipe)) { 1208 1207 urb->iso_frame_desc[td->iso_cnt].actual_length = size; ··· 1209 1214 } 1210 1215 1211 1216 /* check transfer finish */ 1212 - if (check_transfer_finish(td, urb)) { 1217 + if (finish || check_transfer_finish(td, urb)) { 1213 1218 pipe_stop(r8a66597, td->pipe); 1214 1219 pipe_irq_disable(r8a66597, pipenum); 1215 1220 finish = 1;
+3 -11
drivers/usb/host/sl811-hcd.c
··· 438 438 spin_lock(&urb->lock); 439 439 if (urb->status == -EINPROGRESS) 440 440 urb->status = status; 441 - urb->hcpriv = NULL; 442 441 spin_unlock(&urb->lock); 443 442 444 443 usb_hcd_unlink_urb_from_ep(sl811_to_hcd(sl811), urb); ··· 544 545 sl811_read_buf(sl811, SL811HS_PACKET_BUF(bank == 0), 545 546 buf, len); 546 547 usb_dotoggle(udev, ep->epnum, 0); 547 - if (urb->actual_length == urb->transfer_buffer_length) 548 + if (urb->actual_length == urb->transfer_buffer_length 549 + || len < ep->maxpacket) 548 550 urbstat = 0; 549 - else if (len < ep->maxpacket) { 550 - if (urb->transfer_flags & URB_SHORT_NOT_OK) 551 - urbstat = -EREMOTEIO; 552 - else 553 - urbstat = 0; 554 - } 555 - if (usb_pipecontrol(urb->pipe) 556 - && (urbstat == -EREMOTEIO 557 - || urbstat == 0)) { 551 + if (usb_pipecontrol(urb->pipe) && urbstat == 0) { 558 552 559 553 /* NOTE if the status stage STALLs (why?), 560 554 * this reports the wrong urb status.
-5
drivers/usb/host/u132-hcd.c
··· 519 519 struct usb_hcd *hcd = u132_to_hcd(u132); 520 520 urb->error_count = 0; 521 521 urb->status = status; 522 - urb->hcpriv = NULL; 523 522 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 524 523 usb_hcd_unlink_urb_from_ep(hcd, urb); 525 524 endp->queue_next += 1; ··· 559 560 struct usb_hcd *hcd = u132_to_hcd(u132); 560 561 urb->error_count = 0; 561 562 urb->status = status; 562 - urb->hcpriv = NULL; 563 563 spin_lock_irqsave(&endp->queue_lock.slock, irqs); 564 564 usb_hcd_unlink_urb_from_ep(hcd, urb); 565 565 endp->queue_next += 1; ··· 2428 2430 list_del(scan); 2429 2431 endp->queue_size -= 1; 2430 2432 urb->error_count = 0; 2431 - urb->hcpriv = NULL; 2432 2433 usb_hcd_giveback_urb(hcd, urb); 2433 2434 return 0; 2434 2435 } else ··· 2469 2472 endp->edset_flush = 1; 2470 2473 u132_endp_queue_work(u132, endp, 0); 2471 2474 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); 2472 - urb->hcpriv = NULL; 2473 2475 return 0; 2474 2476 } else { 2475 2477 spin_unlock_irqrestore(&endp->queue_lock.slock, irqs); ··· 2513 2517 irqs); 2514 2518 kfree(urbq); 2515 2519 } urb->error_count = 0; 2516 - urb->hcpriv = NULL; 2517 2520 usb_hcd_giveback_urb(hcd, urb); 2518 2521 return 0; 2519 2522 } else if (list_empty(&endp->urb_more)) {
-8
drivers/usb/host/uhci-q.c
··· 757 757 uhci_free_td(uhci, td); 758 758 } 759 759 760 - urbp->urb->hcpriv = NULL; 761 760 kmem_cache_free(uhci_up_cachep, urbp); 762 761 } 763 762 ··· 1493 1494 * unlinked first. Regardless, don't confuse people with a 1494 1495 * negative length. */ 1495 1496 urb->actual_length = max(urb->actual_length, 0); 1496 - 1497 - /* Report erroneous short transfers */ 1498 - if (unlikely((urb->transfer_flags & URB_SHORT_NOT_OK) && 1499 - urb->actual_length < 1500 - urb->transfer_buffer_length && 1501 - urb->status == 0)) 1502 - urb->status = -EREMOTEIO; 1503 1497 } 1504 1498 1505 1499 /* When giving back the first URB in an Isochronous queue,