Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6

* git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6:
USB: prevent autosuspend during hub initialization
USB: Unusual dev for the "Kyocera / Contax SL300R T*" digital camera.
USB: usbtmc: Use explicit unsigned type for input buffer instead of char*
USB: fix crash when URBs are unlinked after the device is gone

+67 -4
+1 -1
drivers/usb/class/usbtmc.c
··· 133 133 134 134 static int usbtmc_ioctl_abort_bulk_in(struct usbtmc_device_data *data) 135 135 { 136 - char *buffer; 136 + u8 *buffer; 137 137 struct device *dev; 138 138 int rv; 139 139 int n;
+32 -3
drivers/usb/core/hcd.c
··· 106 106 /* used when updating an endpoint's URB list */ 107 107 static DEFINE_SPINLOCK(hcd_urb_list_lock); 108 108 109 + /* used to protect against unlinking URBs after the device is gone */ 110 + static DEFINE_SPINLOCK(hcd_urb_unlink_lock); 111 + 109 112 /* wait queue for synchronous unlinks */ 110 113 DECLARE_WAIT_QUEUE_HEAD(usb_kill_urb_queue); 111 114 ··· 1379 1376 int usb_hcd_unlink_urb (struct urb *urb, int status) 1380 1377 { 1381 1378 struct usb_hcd *hcd; 1382 - int retval; 1379 + int retval = -EIDRM; 1380 + unsigned long flags; 1383 1381 1384 - hcd = bus_to_hcd(urb->dev->bus); 1385 - retval = unlink1(hcd, urb, status); 1382 + /* Prevent the device and bus from going away while 1383 + * the unlink is carried out. If they are already gone 1384 + * then urb->use_count must be 0, since disconnected 1385 + * devices can't have any active URBs. 1386 + */ 1387 + spin_lock_irqsave(&hcd_urb_unlink_lock, flags); 1388 + if (atomic_read(&urb->use_count) > 0) { 1389 + retval = 0; 1390 + usb_get_dev(urb->dev); 1391 + } 1392 + spin_unlock_irqrestore(&hcd_urb_unlink_lock, flags); 1393 + if (retval == 0) { 1394 + hcd = bus_to_hcd(urb->dev->bus); 1395 + retval = unlink1(hcd, urb, status); 1396 + usb_put_dev(urb->dev); 1397 + } 1386 1398 1387 1399 if (retval == 0) 1388 1400 retval = -EINPROGRESS; ··· 1544 1526 hcd = bus_to_hcd(udev->bus); 1545 1527 if (hcd->driver->endpoint_disable) 1546 1528 hcd->driver->endpoint_disable(hcd, ep); 1529 + } 1530 + 1531 + /* Protect against drivers that try to unlink URBs after the device 1532 + * is gone, by waiting until all unlinks for @udev are finished. 1533 + * Since we don't currently track URBs by device, simply wait until 1534 + * nothing is running in the locked region of usb_hcd_unlink_urb(). 1535 + */ 1536 + void usb_hcd_synchronize_unlinks(struct usb_device *udev) 1537 + { 1538 + spin_lock_irq(&hcd_urb_unlink_lock); 1539 + spin_unlock_irq(&hcd_urb_unlink_lock); 1547 1540 } 1548 1541 1549 1542 /*-------------------------------------------------------------------------*/
+1
drivers/usb/core/hcd.h
··· 232 232 struct usb_host_endpoint *ep); 233 233 extern void usb_hcd_disable_endpoint(struct usb_device *udev, 234 234 struct usb_host_endpoint *ep); 235 + extern void usb_hcd_synchronize_unlinks(struct usb_device *udev); 235 236 extern int usb_hcd_get_frame_number(struct usb_device *udev); 236 237 237 238 extern struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,
+4
drivers/usb/core/hub.c
··· 659 659 PREPARE_DELAYED_WORK(&hub->init_work, hub_init_func2); 660 660 schedule_delayed_work(&hub->init_work, 661 661 msecs_to_jiffies(delay)); 662 + 663 + /* Suppress autosuspend until init is done */ 664 + to_usb_interface(hub->intfdev)->pm_usage_cnt = 1; 662 665 return; /* Continues at init2: below */ 663 666 } else { 664 667 hub_power_on(hub, true); ··· 1432 1429 */ 1433 1430 dev_dbg (&udev->dev, "unregistering device\n"); 1434 1431 usb_disable_device(udev, 0); 1432 + usb_hcd_synchronize_unlinks(udev); 1435 1433 1436 1434 usb_unlock_device(udev); 1437 1435
+22
drivers/usb/core/urb.c
··· 474 474 * indicating that the request has been canceled (rather than any other 475 475 * code). 476 476 * 477 + * Drivers should not call this routine or related routines, such as 478 + * usb_kill_urb() or usb_unlink_anchored_urbs(), after their disconnect 479 + * method has returned. The disconnect function should synchronize with 480 + * a driver's I/O routines to insure that all URB-related activity has 481 + * completed before it returns. 482 + * 477 483 * This request is always asynchronous. Success is indicated by 478 484 * returning -EINPROGRESS, at which time the URB will probably not yet 479 485 * have been given back to the device driver. When it is eventually ··· 556 550 * This routine may not be used in an interrupt context (such as a bottom 557 551 * half or a completion handler), or when holding a spinlock, or in other 558 552 * situations where the caller can't schedule(). 553 + * 554 + * This routine should not be called by a driver after its disconnect 555 + * method has returned. 559 556 */ 560 557 void usb_kill_urb(struct urb *urb) 561 558 { ··· 597 588 * This routine may not be used in an interrupt context (such as a bottom 598 589 * half or a completion handler), or when holding a spinlock, or in other 599 590 * situations where the caller can't schedule(). 591 + * 592 + * This routine should not be called by a driver after its disconnect 593 + * method has returned. 600 594 */ 601 595 void usb_poison_urb(struct urb *urb) 602 596 { ··· 634 622 * 635 623 * this allows all outstanding URBs to be killed starting 636 624 * from the back of the queue 625 + * 626 + * This routine should not be called by a driver after its disconnect 627 + * method has returned. 637 628 */ 638 629 void usb_kill_anchored_urbs(struct usb_anchor *anchor) 639 630 { ··· 666 651 * this allows all outstanding URBs to be poisoned starting 667 652 * from the back of the queue. Newly added URBs will also be 668 653 * poisoned 654 + * 655 + * This routine should not be called by a driver after its disconnect 656 + * method has returned. 669 657 */ 670 658 void usb_poison_anchored_urbs(struct usb_anchor *anchor) 671 659 { ··· 690 672 spin_unlock_irq(&anchor->lock); 691 673 } 692 674 EXPORT_SYMBOL_GPL(usb_poison_anchored_urbs); 675 + 693 676 /** 694 677 * usb_unlink_anchored_urbs - asynchronously cancel transfer requests en masse 695 678 * @anchor: anchor the requests are bound to ··· 699 680 * from the back of the queue. This function is asynchronous. 700 681 * The unlinking is just tiggered. It may happen after this 701 682 * function has returned. 683 + * 684 + * This routine should not be called by a driver after its disconnect 685 + * method has returned. 702 686 */ 703 687 void usb_unlink_anchored_urbs(struct usb_anchor *anchor) 704 688 {
+7
drivers/usb/storage/unusual_devs.h
··· 333 333 "Finecam S5", 334 334 US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_FIX_INQUIRY), 335 335 336 + /* Patch submitted by Jens Taprogge <jens.taprogge@taprogge.org> */ 337 + UNUSUAL_DEV( 0x0482, 0x0107, 0x0100, 0x0100, 338 + "Kyocera", 339 + "CONTAX SL300R T*", 340 + US_SC_DEVICE, US_PR_DEVICE, NULL, 341 + US_FL_FIX_CAPACITY | US_FL_NOT_LOCKABLE), 342 + 336 343 /* Reported by Paul Stewart <stewart@wetlogic.net> 337 344 * This entry is needed because the device reports Sub=ff */ 338 345 UNUSUAL_DEV( 0x04a4, 0x0004, 0x0001, 0x0001,