aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/misc/usbtest.c
diff options
context:
space:
mode:
authorGustavo A. R. Silva <garsilva@embeddedor.com>2017-04-03 23:51:54 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-04-08 06:04:42 -0400
commit65c7843c942d0990e8b5f40aa4fdc755bbc15034 (patch)
tree18394438eedf9ad817844c2d22df5a223f7441a4 /drivers/usb/misc/usbtest.c
parent2c930e3d0aed1505e86e0928d323df5027817740 (diff)
usb: misc: refactor code
Code refactoring to make the flow easier to follow. Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com> Acked-by: Alan Stern <stern@rowland.harvard.edu> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/misc/usbtest.c')
-rw-r--r--drivers/usb/misc/usbtest.c49
1 files changed, 21 insertions, 28 deletions
diff --git a/drivers/usb/misc/usbtest.c b/drivers/usb/misc/usbtest.c
index 26ae5d1a2a4e..eee82ca55b7b 100644
--- a/drivers/usb/misc/usbtest.c
+++ b/drivers/usb/misc/usbtest.c
@@ -124,6 +124,20 @@ static struct usb_device *testdev_to_usbdev(struct usbtest_dev *test)
124 124
125/*-------------------------------------------------------------------------*/ 125/*-------------------------------------------------------------------------*/
126 126
127static inline void endpoint_update(int edi,
128 struct usb_host_endpoint **in,
129 struct usb_host_endpoint **out,
130 struct usb_host_endpoint *e)
131{
132 if (edi) {
133 if (!*in)
134 *in = e;
135 } else {
136 if (!*out)
137 *out = e;
138 }
139}
140
127static int 141static int
128get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf) 142get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
129{ 143{
@@ -151,47 +165,26 @@ get_endpoints(struct usbtest_dev *dev, struct usb_interface *intf)
151 */ 165 */
152 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) { 166 for (ep = 0; ep < alt->desc.bNumEndpoints; ep++) {
153 struct usb_host_endpoint *e; 167 struct usb_host_endpoint *e;
168 int edi;
154 169
155 e = alt->endpoint + ep; 170 e = alt->endpoint + ep;
171 edi = usb_endpoint_dir_in(&e->desc);
172
156 switch (usb_endpoint_type(&e->desc)) { 173 switch (usb_endpoint_type(&e->desc)) {
157 case USB_ENDPOINT_XFER_BULK: 174 case USB_ENDPOINT_XFER_BULK:
158 break; 175 endpoint_update(edi, &in, &out, e);
176 continue;
159 case USB_ENDPOINT_XFER_INT: 177 case USB_ENDPOINT_XFER_INT:
160 if (dev->info->intr) 178 if (dev->info->intr)
161 goto try_intr; 179 endpoint_update(edi, &int_in, &int_out, e);
162 continue; 180 continue;
163 case USB_ENDPOINT_XFER_ISOC: 181 case USB_ENDPOINT_XFER_ISOC:
164 if (dev->info->iso) 182 if (dev->info->iso)
165 goto try_iso; 183 endpoint_update(edi, &iso_in, &iso_out, e);
166 /* FALLTHROUGH */ 184 /* FALLTHROUGH */
167 default: 185 default:
168 continue; 186 continue;
169 } 187 }
170 if (usb_endpoint_dir_in(&e->desc)) {
171 if (!in)
172 in = e;
173 } else {
174 if (!out)
175 out = e;
176 }
177 continue;
178try_intr:
179 if (usb_endpoint_dir_in(&e->desc)) {
180 if (!int_in)
181 int_in = e;
182 } else {
183 if (!int_out)
184 int_out = e;
185 }
186 continue;
187try_iso:
188 if (usb_endpoint_dir_in(&e->desc)) {
189 if (!iso_in)
190 iso_in = e;
191 } else {
192 if (!iso_out)
193 iso_out = e;
194 }
195 } 188 }
196 if ((in && out) || iso_in || iso_out || int_in || int_out) 189 if ((in && out) || iso_in || iso_out || int_in || int_out)
197 goto found; 190 goto found;