diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/usb/core/urb.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c index 47903d510955..8b800e34407b 100644 --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c | |||
@@ -187,6 +187,31 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb); | |||
187 | 187 | ||
188 | /*-------------------------------------------------------------------*/ | 188 | /*-------------------------------------------------------------------*/ |
189 | 189 | ||
190 | static const int pipetypes[4] = { | ||
191 | PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT | ||
192 | }; | ||
193 | |||
194 | /** | ||
195 | * usb_urb_ep_type_check - sanity check of endpoint in the given urb | ||
196 | * @urb: urb to be checked | ||
197 | * | ||
198 | * This performs a light-weight sanity check for the endpoint in the | ||
199 | * given urb. It returns 0 if the urb contains a valid endpoint, otherwise | ||
200 | * a negative error code. | ||
201 | */ | ||
202 | int usb_urb_ep_type_check(const struct urb *urb) | ||
203 | { | ||
204 | const struct usb_host_endpoint *ep; | ||
205 | |||
206 | ep = usb_pipe_endpoint(urb->dev, urb->pipe); | ||
207 | if (!ep) | ||
208 | return -EINVAL; | ||
209 | if (usb_pipetype(urb->pipe) != pipetypes[usb_endpoint_type(&ep->desc)]) | ||
210 | return -EINVAL; | ||
211 | return 0; | ||
212 | } | ||
213 | EXPORT_SYMBOL_GPL(usb_urb_ep_type_check); | ||
214 | |||
190 | /** | 215 | /** |
191 | * usb_submit_urb - issue an asynchronous transfer request for an endpoint | 216 | * usb_submit_urb - issue an asynchronous transfer request for an endpoint |
192 | * @urb: pointer to the urb describing the request | 217 | * @urb: pointer to the urb describing the request |
@@ -326,9 +351,6 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb); | |||
326 | */ | 351 | */ |
327 | int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | 352 | int usb_submit_urb(struct urb *urb, gfp_t mem_flags) |
328 | { | 353 | { |
329 | static int pipetypes[4] = { | ||
330 | PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT | ||
331 | }; | ||
332 | int xfertype, max; | 354 | int xfertype, max; |
333 | struct usb_device *dev; | 355 | struct usb_device *dev; |
334 | struct usb_host_endpoint *ep; | 356 | struct usb_host_endpoint *ep; |
@@ -444,7 +466,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) | |||
444 | */ | 466 | */ |
445 | 467 | ||
446 | /* Check that the pipe's type matches the endpoint's type */ | 468 | /* Check that the pipe's type matches the endpoint's type */ |
447 | if (usb_pipetype(urb->pipe) != pipetypes[xfertype]) | 469 | if (usb_urb_ep_type_check(urb)) |
448 | dev_WARN(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n", | 470 | dev_WARN(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n", |
449 | usb_pipetype(urb->pipe), pipetypes[xfertype]); | 471 | usb_pipetype(urb->pipe), pipetypes[xfertype]); |
450 | 472 | ||