hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/usb/core/urb.c
....@@ -71,9 +71,8 @@
7171 {
7272 struct urb *urb;
7373
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);
7776 if (!urb)
7877 return NULL;
7978 usb_init_urb(urb);
....@@ -193,6 +192,28 @@
193192 };
194193
195194 /**
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
+/**
196217 * usb_urb_ep_type_check - sanity check of endpoint in the given urb
197218 * @urb: urb to be checked
198219 *
....@@ -202,14 +223,7 @@
202223 */
203224 int usb_urb_ep_type_check(const struct urb *urb)
204225 {
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);
213227 }
214228 EXPORT_SYMBOL_GPL(usb_urb_ep_type_check);
215229
....@@ -475,7 +489,7 @@
475489 */
476490
477491 /* 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))
479493 dev_WARN(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n",
480494 usb_pipetype(urb->pipe), pipetypes[xfertype]);
481495
....@@ -487,7 +501,7 @@
487501 case USB_ENDPOINT_XFER_INT:
488502 if (is_out)
489503 allowed |= URB_ZERO_PACKET;
490
- /* FALLTHROUGH */
504
+ fallthrough;
491505 default: /* all non-iso endpoints */
492506 if (!is_out)
493507 allowed |= URB_SHORT_NOT_OK;
....@@ -520,7 +534,7 @@
520534 if ((urb->interval < 6)
521535 && (xfertype == USB_ENDPOINT_XFER_INT))
522536 return -EINVAL;
523
- /* fall through */
537
+ fallthrough;
524538 default:
525539 if (urb->interval <= 0)
526540 return -EINVAL;