Merge tag 'usb-5.16-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb

Pull USB fixes from Greg KH:
"Here are some small USB fixes for 5.16-rc5. They include:

- gadget driver fixes for reported issues

- xhci fixes for reported problems.

- config endpoint parsing fixes for where we got bitfields wrong

Most of these have been in linux-next, the remaining few were not, but
got lots of local testing in my systems and in some cloud testing
infrastructures"

* tag 'usb-5.16-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb:
usb: core: config: using bit mask instead of individual bits
usb: core: config: fix validation of wMaxPacketValue entries
USB: gadget: zero allocate endpoint 0 buffers
USB: gadget: detect too-big endpoint 0 requests
xhci: avoid race between disable slot command and host runtime suspend
xhci: Remove CONFIG_USB_DEFAULT_PERSIST to prevent xHCI from runtime suspending
Revert "usb: dwc3: dwc3-qcom: Enable tx-fifo-resize property by default"

Changed files
+61 -33
drivers
+3 -3
drivers/usb/core/config.c
··· 406 406 * the USB-2 spec requires such endpoints to have wMaxPacketSize = 0 407 407 * (see the end of section 5.6.3), so don't warn about them. 408 408 */ 409 - maxp = usb_endpoint_maxp(&endpoint->desc); 409 + maxp = le16_to_cpu(endpoint->desc.wMaxPacketSize); 410 410 if (maxp == 0 && !(usb_endpoint_xfer_isoc(d) && asnum == 0)) { 411 411 dev_warn(ddev, "config %d interface %d altsetting %d endpoint 0x%X has invalid wMaxPacketSize 0\n", 412 412 cfgno, inum, asnum, d->bEndpointAddress); ··· 422 422 maxpacket_maxes = full_speed_maxpacket_maxes; 423 423 break; 424 424 case USB_SPEED_HIGH: 425 - /* Bits 12..11 are allowed only for HS periodic endpoints */ 425 + /* Multiple-transactions bits are allowed only for HS periodic endpoints */ 426 426 if (usb_endpoint_xfer_int(d) || usb_endpoint_xfer_isoc(d)) { 427 - i = maxp & (BIT(12) | BIT(11)); 427 + i = maxp & USB_EP_MAXP_MULT_MASK; 428 428 maxp &= ~i; 429 429 } 430 430 fallthrough;
-15
drivers/usb/dwc3/dwc3-qcom.c
··· 649 649 struct dwc3_qcom *qcom = platform_get_drvdata(pdev); 650 650 struct device_node *np = pdev->dev.of_node, *dwc3_np; 651 651 struct device *dev = &pdev->dev; 652 - struct property *prop; 653 652 int ret; 654 653 655 654 dwc3_np = of_get_compatible_child(np, "snps,dwc3"); 656 655 if (!dwc3_np) { 657 656 dev_err(dev, "failed to find dwc3 core child\n"); 658 657 return -ENODEV; 659 - } 660 - 661 - prop = devm_kzalloc(dev, sizeof(*prop), GFP_KERNEL); 662 - if (!prop) { 663 - ret = -ENOMEM; 664 - dev_err(dev, "unable to allocate memory for property\n"); 665 - goto node_put; 666 - } 667 - 668 - prop->name = "tx-fifo-resize"; 669 - ret = of_add_property(dwc3_np, prop); 670 - if (ret) { 671 - dev_err(dev, "unable to add property\n"); 672 - goto node_put; 673 658 } 674 659 675 660 ret = of_platform_populate(np, NULL, NULL, dev);
+13 -1
drivers/usb/gadget/composite.c
··· 1679 1679 struct usb_function *f = NULL; 1680 1680 u8 endp; 1681 1681 1682 + if (w_length > USB_COMP_EP0_BUFSIZ) { 1683 + if (ctrl->bRequestType == USB_DIR_OUT) { 1684 + goto done; 1685 + } else { 1686 + /* Cast away the const, we are going to overwrite on purpose. */ 1687 + __le16 *temp = (__le16 *)&ctrl->wLength; 1688 + 1689 + *temp = cpu_to_le16(USB_COMP_EP0_BUFSIZ); 1690 + w_length = USB_COMP_EP0_BUFSIZ; 1691 + } 1692 + } 1693 + 1682 1694 /* partial re-init of the response message; the function or the 1683 1695 * gadget might need to intercept e.g. a control-OUT completion 1684 1696 * when we delegate to it. ··· 2221 2209 if (!cdev->req) 2222 2210 return -ENOMEM; 2223 2211 2224 - cdev->req->buf = kmalloc(USB_COMP_EP0_BUFSIZ, GFP_KERNEL); 2212 + cdev->req->buf = kzalloc(USB_COMP_EP0_BUFSIZ, GFP_KERNEL); 2225 2213 if (!cdev->req->buf) 2226 2214 goto fail; 2227 2215
+14 -1
drivers/usb/gadget/legacy/dbgp.c
··· 137 137 goto fail_1; 138 138 } 139 139 140 - req->buf = kmalloc(DBGP_REQ_LEN, GFP_KERNEL); 140 + req->buf = kzalloc(DBGP_REQ_LEN, GFP_KERNEL); 141 141 if (!req->buf) { 142 142 err = -ENOMEM; 143 143 stp = 2; ··· 344 344 int err = -EOPNOTSUPP; 345 345 void *data = NULL; 346 346 u16 len = 0; 347 + 348 + if (length > DBGP_REQ_LEN) { 349 + if (ctrl->bRequestType == USB_DIR_OUT) { 350 + return err; 351 + } else { 352 + /* Cast away the const, we are going to overwrite on purpose. */ 353 + __le16 *temp = (__le16 *)&ctrl->wLength; 354 + 355 + *temp = cpu_to_le16(DBGP_REQ_LEN); 356 + length = DBGP_REQ_LEN; 357 + } 358 + } 359 + 347 360 348 361 if (request == USB_REQ_GET_DESCRIPTOR) { 349 362 switch (value>>8) {
+15 -1
drivers/usb/gadget/legacy/inode.c
··· 110 110 /* enough for the whole queue: most events invalidate others */ 111 111 #define N_EVENT 5 112 112 113 + #define RBUF_SIZE 256 114 + 113 115 struct dev_data { 114 116 spinlock_t lock; 115 117 refcount_t count; ··· 146 144 struct dentry *dentry; 147 145 148 146 /* except this scratch i/o buffer for ep0 */ 149 - u8 rbuf [256]; 147 + u8 rbuf[RBUF_SIZE]; 150 148 }; 151 149 152 150 static inline void get_dev (struct dev_data *data) ··· 1332 1330 struct usb_gadgetfs_event *event; 1333 1331 u16 w_value = le16_to_cpu(ctrl->wValue); 1334 1332 u16 w_length = le16_to_cpu(ctrl->wLength); 1333 + 1334 + if (w_length > RBUF_SIZE) { 1335 + if (ctrl->bRequestType == USB_DIR_OUT) { 1336 + return value; 1337 + } else { 1338 + /* Cast away the const, we are going to overwrite on purpose. */ 1339 + __le16 *temp = (__le16 *)&ctrl->wLength; 1340 + 1341 + *temp = cpu_to_le16(RBUF_SIZE); 1342 + w_length = RBUF_SIZE; 1343 + } 1344 + } 1335 1345 1336 1346 spin_lock (&dev->lock); 1337 1347 dev->setup_abort = 0;
+1
drivers/usb/host/xhci-hub.c
··· 717 717 continue; 718 718 719 719 retval = xhci_disable_slot(xhci, i); 720 + xhci_free_virt_device(xhci, i); 720 721 if (retval) 721 722 xhci_err(xhci, "Failed to disable slot %d, %d. Enter test mode anyway\n", 722 723 i, retval);
-1
drivers/usb/host/xhci-ring.c
··· 1525 1525 if (xhci->quirks & XHCI_EP_LIMIT_QUIRK) 1526 1526 /* Delete default control endpoint resources */ 1527 1527 xhci_free_device_endpoint_resources(xhci, virt_dev, true); 1528 - xhci_free_virt_device(xhci, slot_id); 1529 1528 } 1530 1529 1531 1530 static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id,
+15 -11
drivers/usb/host/xhci.c
··· 3934 3934 struct xhci_slot_ctx *slot_ctx; 3935 3935 int i, ret; 3936 3936 3937 - #ifndef CONFIG_USB_DEFAULT_PERSIST 3938 3937 /* 3939 3938 * We called pm_runtime_get_noresume when the device was attached. 3940 3939 * Decrement the counter here to allow controller to runtime suspend ··· 3941 3942 */ 3942 3943 if (xhci->quirks & XHCI_RESET_ON_RESUME) 3943 3944 pm_runtime_put_noidle(hcd->self.controller); 3944 - #endif 3945 3945 3946 3946 ret = xhci_check_args(hcd, udev, NULL, 0, true, __func__); 3947 3947 /* If the host is halted due to driver unload, we still need to free the ··· 3959 3961 del_timer_sync(&virt_dev->eps[i].stop_cmd_timer); 3960 3962 } 3961 3963 virt_dev->udev = NULL; 3962 - ret = xhci_disable_slot(xhci, udev->slot_id); 3963 - if (ret) 3964 - xhci_free_virt_device(xhci, udev->slot_id); 3964 + xhci_disable_slot(xhci, udev->slot_id); 3965 + xhci_free_virt_device(xhci, udev->slot_id); 3965 3966 } 3966 3967 3967 3968 int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id) ··· 3970 3973 u32 state; 3971 3974 int ret = 0; 3972 3975 3973 - command = xhci_alloc_command(xhci, false, GFP_KERNEL); 3976 + command = xhci_alloc_command(xhci, true, GFP_KERNEL); 3974 3977 if (!command) 3975 3978 return -ENOMEM; 3976 3979 ··· 3995 3998 } 3996 3999 xhci_ring_cmd_db(xhci); 3997 4000 spin_unlock_irqrestore(&xhci->lock, flags); 4001 + 4002 + wait_for_completion(command->completion); 4003 + 4004 + if (command->status != COMP_SUCCESS) 4005 + xhci_warn(xhci, "Unsuccessful disable slot %u command, status %d\n", 4006 + slot_id, command->status); 4007 + 4008 + xhci_free_command(xhci, command); 4009 + 3998 4010 return ret; 3999 4011 } 4000 4012 ··· 4100 4094 4101 4095 xhci_debugfs_create_slot(xhci, slot_id); 4102 4096 4103 - #ifndef CONFIG_USB_DEFAULT_PERSIST 4104 4097 /* 4105 4098 * If resetting upon resume, we can't put the controller into runtime 4106 4099 * suspend if there is a device attached. 4107 4100 */ 4108 4101 if (xhci->quirks & XHCI_RESET_ON_RESUME) 4109 4102 pm_runtime_get_noresume(hcd->self.controller); 4110 - #endif 4111 4103 4112 4104 /* Is this a LS or FS device under a HS hub? */ 4113 4105 /* Hub or peripherial? */ 4114 4106 return 1; 4115 4107 4116 4108 disable_slot: 4117 - ret = xhci_disable_slot(xhci, udev->slot_id); 4118 - if (ret) 4119 - xhci_free_virt_device(xhci, udev->slot_id); 4109 + xhci_disable_slot(xhci, udev->slot_id); 4110 + xhci_free_virt_device(xhci, udev->slot_id); 4120 4111 4121 4112 return 0; 4122 4113 } ··· 4243 4240 4244 4241 mutex_unlock(&xhci->mutex); 4245 4242 ret = xhci_disable_slot(xhci, udev->slot_id); 4243 + xhci_free_virt_device(xhci, udev->slot_id); 4246 4244 if (!ret) 4247 4245 xhci_alloc_dev(hcd, udev); 4248 4246 kfree(command->completion);