.. | .. |
---|
71 | 71 | { |
---|
72 | 72 | struct urb *urb; |
---|
73 | 73 | |
---|
74 | | - urb = kmalloc(sizeof(struct urb) + |
---|
75 | | - iso_packets * sizeof(struct usb_iso_packet_descriptor), |
---|
76 | | - mem_flags); |
---|
| 74 | + urb = kmalloc(struct_size(urb, iso_frame_desc, iso_packets), |
---|
| 75 | + mem_flags); |
---|
77 | 76 | if (!urb) |
---|
78 | 77 | return NULL; |
---|
79 | 78 | usb_init_urb(urb); |
---|
.. | .. |
---|
193 | 192 | }; |
---|
194 | 193 | |
---|
195 | 194 | /** |
---|
| 195 | + * usb_pipe_type_check - sanity check of a specific pipe for a usb device |
---|
| 196 | + * @dev: struct usb_device to be checked |
---|
| 197 | + * @pipe: pipe to check |
---|
| 198 | + * |
---|
| 199 | + * This performs a light-weight sanity check for the endpoint in the |
---|
| 200 | + * given usb device. It returns 0 if the pipe is valid for the specific usb |
---|
| 201 | + * device, otherwise a negative error code. |
---|
| 202 | + */ |
---|
| 203 | +int usb_pipe_type_check(struct usb_device *dev, unsigned int pipe) |
---|
| 204 | +{ |
---|
| 205 | + const struct usb_host_endpoint *ep; |
---|
| 206 | + |
---|
| 207 | + ep = usb_pipe_endpoint(dev, pipe); |
---|
| 208 | + if (!ep) |
---|
| 209 | + return -EINVAL; |
---|
| 210 | + if (usb_pipetype(pipe) != pipetypes[usb_endpoint_type(&ep->desc)]) |
---|
| 211 | + return -EINVAL; |
---|
| 212 | + return 0; |
---|
| 213 | +} |
---|
| 214 | +EXPORT_SYMBOL_GPL(usb_pipe_type_check); |
---|
| 215 | + |
---|
| 216 | +/** |
---|
196 | 217 | * usb_urb_ep_type_check - sanity check of endpoint in the given urb |
---|
197 | 218 | * @urb: urb to be checked |
---|
198 | 219 | * |
---|
.. | .. |
---|
202 | 223 | */ |
---|
203 | 224 | int usb_urb_ep_type_check(const struct urb *urb) |
---|
204 | 225 | { |
---|
205 | | - const struct usb_host_endpoint *ep; |
---|
206 | | - |
---|
207 | | - ep = usb_pipe_endpoint(urb->dev, urb->pipe); |
---|
208 | | - if (!ep) |
---|
209 | | - return -EINVAL; |
---|
210 | | - if (usb_pipetype(urb->pipe) != pipetypes[usb_endpoint_type(&ep->desc)]) |
---|
211 | | - return -EINVAL; |
---|
212 | | - return 0; |
---|
| 226 | + return usb_pipe_type_check(urb->dev, urb->pipe); |
---|
213 | 227 | } |
---|
214 | 228 | EXPORT_SYMBOL_GPL(usb_urb_ep_type_check); |
---|
215 | 229 | |
---|
.. | .. |
---|
475 | 489 | */ |
---|
476 | 490 | |
---|
477 | 491 | /* Check that the pipe's type matches the endpoint's type */ |
---|
478 | | - if (usb_urb_ep_type_check(urb)) |
---|
| 492 | + if (usb_pipe_type_check(urb->dev, urb->pipe)) |
---|
479 | 493 | dev_WARN(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n", |
---|
480 | 494 | usb_pipetype(urb->pipe), pipetypes[xfertype]); |
---|
481 | 495 | |
---|
.. | .. |
---|
487 | 501 | case USB_ENDPOINT_XFER_INT: |
---|
488 | 502 | if (is_out) |
---|
489 | 503 | allowed |= URB_ZERO_PACKET; |
---|
490 | | - /* FALLTHROUGH */ |
---|
| 504 | + fallthrough; |
---|
491 | 505 | default: /* all non-iso endpoints */ |
---|
492 | 506 | if (!is_out) |
---|
493 | 507 | allowed |= URB_SHORT_NOT_OK; |
---|
.. | .. |
---|
520 | 534 | if ((urb->interval < 6) |
---|
521 | 535 | && (xfertype == USB_ENDPOINT_XFER_INT)) |
---|
522 | 536 | return -EINVAL; |
---|
523 | | - /* fall through */ |
---|
| 537 | + fallthrough; |
---|
524 | 538 | default: |
---|
525 | 539 | if (urb->interval <= 0) |
---|
526 | 540 | return -EINVAL; |
---|