diff options
author | Johan Hovold <johan@kernel.org> | 2017-03-17 06:35:49 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-03-23 08:54:08 -0400 |
commit | 80070a408ca34b2fe7aed30a3fa38dd19ece8197 (patch) | |
tree | ca1c7debf57205e4b1224aa81130be4fe133118e | |
parent | f8d8464bfc90e058fe68dee02121d46f661f68cd (diff) |
USB: storage: refactor endpoint retrieval
Use the new endpoint helpers to lookup the required bulk-in and bulk-out
endpoints and the (typically) optional interrupt-in endpoint.
Cc: usb-storage@lists.one-eyed-alien.net
Signed-off-by: Johan Hovold <johan@kernel.org>
Acked-by: Alan Stern <stern@rowland.harvard.edu>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/usb/storage/usb.c | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c index 615bea08ec0a..06615934fed1 100644 --- a/drivers/usb/storage/usb.c +++ b/drivers/usb/storage/usb.c | |||
@@ -737,13 +737,11 @@ static void get_protocol(struct us_data *us) | |||
737 | /* Get the pipe settings */ | 737 | /* Get the pipe settings */ |
738 | static int get_pipes(struct us_data *us) | 738 | static int get_pipes(struct us_data *us) |
739 | { | 739 | { |
740 | struct usb_host_interface *altsetting = | 740 | struct usb_host_interface *alt = us->pusb_intf->cur_altsetting; |
741 | us->pusb_intf->cur_altsetting; | 741 | struct usb_endpoint_descriptor *ep_in; |
742 | int i; | 742 | struct usb_endpoint_descriptor *ep_out; |
743 | struct usb_endpoint_descriptor *ep; | 743 | struct usb_endpoint_descriptor *ep_int; |
744 | struct usb_endpoint_descriptor *ep_in = NULL; | 744 | int res; |
745 | struct usb_endpoint_descriptor *ep_out = NULL; | ||
746 | struct usb_endpoint_descriptor *ep_int = NULL; | ||
747 | 745 | ||
748 | /* | 746 | /* |
749 | * Find the first endpoint of each type we need. | 747 | * Find the first endpoint of each type we need. |
@@ -751,28 +749,16 @@ static int get_pipes(struct us_data *us) | |||
751 | * An optional interrupt-in is OK (necessary for CBI protocol). | 749 | * An optional interrupt-in is OK (necessary for CBI protocol). |
752 | * We will ignore any others. | 750 | * We will ignore any others. |
753 | */ | 751 | */ |
754 | for (i = 0; i < altsetting->desc.bNumEndpoints; i++) { | 752 | res = usb_find_common_endpoints(alt, &ep_in, &ep_out, NULL, NULL); |
755 | ep = &altsetting->endpoint[i].desc; | 753 | if (res) { |
756 | 754 | usb_stor_dbg(us, "bulk endpoints not found\n"); | |
757 | if (usb_endpoint_xfer_bulk(ep)) { | 755 | return res; |
758 | if (usb_endpoint_dir_in(ep)) { | ||
759 | if (!ep_in) | ||
760 | ep_in = ep; | ||
761 | } else { | ||
762 | if (!ep_out) | ||
763 | ep_out = ep; | ||
764 | } | ||
765 | } | ||
766 | |||
767 | else if (usb_endpoint_is_int_in(ep)) { | ||
768 | if (!ep_int) | ||
769 | ep_int = ep; | ||
770 | } | ||
771 | } | 756 | } |
772 | 757 | ||
773 | if (!ep_in || !ep_out || (us->protocol == USB_PR_CBI && !ep_int)) { | 758 | res = usb_find_int_in_endpoint(alt, &ep_int); |
774 | usb_stor_dbg(us, "Endpoint sanity check failed! Rejecting dev.\n"); | 759 | if (res && us->protocol == USB_PR_CBI) { |
775 | return -EIO; | 760 | usb_stor_dbg(us, "interrupt endpoint not found\n"); |
761 | return res; | ||
776 | } | 762 | } |
777 | 763 | ||
778 | /* Calculate and store the pipe values */ | 764 | /* Calculate and store the pipe values */ |