diff options
author | Matthew Wilcox <matthew@wil.cx> | 2010-12-15 15:44:05 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2010-12-15 18:26:44 -0500 |
commit | 89dc29051b626756e69db12f3ffb22e49a817bfe (patch) | |
tree | 99b2d431a73b4c6a1a1e17079b1c09e8ccf8c30b /drivers/usb | |
parent | 92a3f767f5cd079351ae04a337c40266e9c6048f (diff) |
USB: uas: Ensure we only bind to a UAS interface
While all existing UAS devices use alternate interface 1, this is not
guaranteed, and it has caused confusion with people trying to bind the
uas driver to non-uas devices.
Signed-off-by: Matthew Wilcox <willy@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r-- | drivers/usb/storage/uas.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c index 06409a6ca2f4..52e5ec1b2e8a 100644 --- a/drivers/usb/storage/uas.c +++ b/drivers/usb/storage/uas.c | |||
@@ -582,6 +582,34 @@ static struct usb_device_id uas_usb_ids[] = { | |||
582 | }; | 582 | }; |
583 | MODULE_DEVICE_TABLE(usb, uas_usb_ids); | 583 | MODULE_DEVICE_TABLE(usb, uas_usb_ids); |
584 | 584 | ||
585 | static int uas_is_interface(struct usb_host_interface *intf) | ||
586 | { | ||
587 | return (intf->desc.bInterfaceClass == USB_CLASS_MASS_STORAGE && | ||
588 | intf->desc.bInterfaceSubClass == USB_SC_SCSI && | ||
589 | intf->desc.bInterfaceProtocol == USB_PR_UAS); | ||
590 | } | ||
591 | |||
592 | static int uas_switch_interface(struct usb_device *udev, | ||
593 | struct usb_interface *intf) | ||
594 | { | ||
595 | int i; | ||
596 | |||
597 | if (uas_is_interface(intf->cur_altsetting)) | ||
598 | return 0; | ||
599 | |||
600 | for (i = 0; i < intf->num_altsetting; i++) { | ||
601 | struct usb_host_interface *alt = &intf->altsetting[i]; | ||
602 | if (alt == intf->cur_altsetting) | ||
603 | continue; | ||
604 | if (uas_is_interface(alt)) | ||
605 | return usb_set_interface(udev, | ||
606 | alt->desc.bInterfaceNumber, | ||
607 | alt->desc.bAlternateSetting); | ||
608 | } | ||
609 | |||
610 | return -ENODEV; | ||
611 | } | ||
612 | |||
585 | static void uas_configure_endpoints(struct uas_dev_info *devinfo) | 613 | static void uas_configure_endpoints(struct uas_dev_info *devinfo) |
586 | { | 614 | { |
587 | struct usb_host_endpoint *eps[4] = { }; | 615 | struct usb_host_endpoint *eps[4] = { }; |
@@ -655,13 +683,8 @@ static int uas_probe(struct usb_interface *intf, const struct usb_device_id *id) | |||
655 | struct uas_dev_info *devinfo; | 683 | struct uas_dev_info *devinfo; |
656 | struct usb_device *udev = interface_to_usbdev(intf); | 684 | struct usb_device *udev = interface_to_usbdev(intf); |
657 | 685 | ||
658 | if (id->bInterfaceProtocol == 0x50) { | 686 | if (uas_switch_interface(udev, intf)) |
659 | int ifnum = intf->cur_altsetting->desc.bInterfaceNumber; | 687 | return -ENODEV; |
660 | /* XXX: Shouldn't assume that 1 is the alternative we want */ | ||
661 | int ret = usb_set_interface(udev, ifnum, 1); | ||
662 | if (ret) | ||
663 | return -ENODEV; | ||
664 | } | ||
665 | 688 | ||
666 | devinfo = kmalloc(sizeof(struct uas_dev_info), GFP_KERNEL); | 689 | devinfo = kmalloc(sizeof(struct uas_dev_info), GFP_KERNEL); |
667 | if (!devinfo) | 690 | if (!devinfo) |