Skip to content

Commit 90d9fbc

Browse files
committed
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"
2 parents 8d7ed10 + ca57373 commit 90d9fbc

File tree

8 files changed

+61
-33
lines changed

8 files changed

+61
-33
lines changed

drivers/usb/core/config.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno,
406406
* the USB-2 spec requires such endpoints to have wMaxPacketSize = 0
407407
* (see the end of section 5.6.3), so don't warn about them.
408408
*/
409-
maxp = usb_endpoint_maxp(&endpoint->desc);
409+
maxp = le16_to_cpu(endpoint->desc.wMaxPacketSize);
410410
if (maxp == 0 && !(usb_endpoint_xfer_isoc(d) && asnum == 0)) {
411411
dev_warn(ddev, "config %d interface %d altsetting %d endpoint 0x%X has invalid wMaxPacketSize 0\n",
412412
cfgno, inum, asnum, d->bEndpointAddress);
@@ -422,9 +422,9 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno,
422422
maxpacket_maxes = full_speed_maxpacket_maxes;
423423
break;
424424
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 */
426426
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;
428428
maxp &= ~i;
429429
}
430430
fallthrough;

drivers/usb/dwc3/dwc3-qcom.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,6 @@ static int dwc3_qcom_of_register_core(struct platform_device *pdev)
649649
struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
650650
struct device_node *np = pdev->dev.of_node, *dwc3_np;
651651
struct device *dev = &pdev->dev;
652-
struct property *prop;
653652
int ret;
654653

655654
dwc3_np = of_get_compatible_child(np, "snps,dwc3");
@@ -658,20 +657,6 @@ static int dwc3_qcom_of_register_core(struct platform_device *pdev)
658657
return -ENODEV;
659658
}
660659

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-
}
674-
675660
ret = of_platform_populate(np, NULL, NULL, dev);
676661
if (ret) {
677662
dev_err(dev, "failed to register dwc3 core - %d\n", ret);

drivers/usb/gadget/composite.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,18 @@ composite_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
16791679
struct usb_function *f = NULL;
16801680
u8 endp;
16811681

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+
16821694
/* partial re-init of the response message; the function or the
16831695
* gadget might need to intercept e.g. a control-OUT completion
16841696
* when we delegate to it.
@@ -2209,7 +2221,7 @@ int composite_dev_prepare(struct usb_composite_driver *composite,
22092221
if (!cdev->req)
22102222
return -ENOMEM;
22112223

2212-
cdev->req->buf = kmalloc(USB_COMP_EP0_BUFSIZ, GFP_KERNEL);
2224+
cdev->req->buf = kzalloc(USB_COMP_EP0_BUFSIZ, GFP_KERNEL);
22132225
if (!cdev->req->buf)
22142226
goto fail;
22152227

drivers/usb/gadget/legacy/dbgp.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static int dbgp_enable_ep_req(struct usb_ep *ep)
137137
goto fail_1;
138138
}
139139

140-
req->buf = kmalloc(DBGP_REQ_LEN, GFP_KERNEL);
140+
req->buf = kzalloc(DBGP_REQ_LEN, GFP_KERNEL);
141141
if (!req->buf) {
142142
err = -ENOMEM;
143143
stp = 2;
@@ -345,6 +345,19 @@ static int dbgp_setup(struct usb_gadget *gadget,
345345
void *data = NULL;
346346
u16 len = 0;
347347

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+
360+
348361
if (request == USB_REQ_GET_DESCRIPTOR) {
349362
switch (value>>8) {
350363
case USB_DT_DEVICE:

drivers/usb/gadget/legacy/inode.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ enum ep0_state {
110110
/* enough for the whole queue: most events invalidate others */
111111
#define N_EVENT 5
112112

113+
#define RBUF_SIZE 256
114+
113115
struct dev_data {
114116
spinlock_t lock;
115117
refcount_t count;
@@ -144,7 +146,7 @@ struct dev_data {
144146
struct dentry *dentry;
145147

146148
/* except this scratch i/o buffer for ep0 */
147-
u8 rbuf [256];
149+
u8 rbuf[RBUF_SIZE];
148150
};
149151

150152
static inline void get_dev (struct dev_data *data)
@@ -1331,6 +1333,18 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
13311333
u16 w_value = le16_to_cpu(ctrl->wValue);
13321334
u16 w_length = le16_to_cpu(ctrl->wLength);
13331335

1336+
if (w_length > RBUF_SIZE) {
1337+
if (ctrl->bRequestType == USB_DIR_OUT) {
1338+
return value;
1339+
} else {
1340+
/* Cast away the const, we are going to overwrite on purpose. */
1341+
__le16 *temp = (__le16 *)&ctrl->wLength;
1342+
1343+
*temp = cpu_to_le16(RBUF_SIZE);
1344+
w_length = RBUF_SIZE;
1345+
}
1346+
}
1347+
13341348
spin_lock (&dev->lock);
13351349
dev->setup_abort = 0;
13361350
if (dev->state == STATE_DEV_UNCONNECTED) {

drivers/usb/host/xhci-hub.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ static int xhci_enter_test_mode(struct xhci_hcd *xhci,
717717
continue;
718718

719719
retval = xhci_disable_slot(xhci, i);
720+
xhci_free_virt_device(xhci, i);
720721
if (retval)
721722
xhci_err(xhci, "Failed to disable slot %d, %d. Enter test mode anyway\n",
722723
i, retval);

drivers/usb/host/xhci-ring.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,6 @@ static void xhci_handle_cmd_disable_slot(struct xhci_hcd *xhci, int slot_id)
15251525
if (xhci->quirks & XHCI_EP_LIMIT_QUIRK)
15261526
/* Delete default control endpoint resources */
15271527
xhci_free_device_endpoint_resources(xhci, virt_dev, true);
1528-
xhci_free_virt_device(xhci, slot_id);
15291528
}
15301529

15311530
static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id,

drivers/usb/host/xhci.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3934,15 +3934,13 @@ static void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
39343934
struct xhci_slot_ctx *slot_ctx;
39353935
int i, ret;
39363936

3937-
#ifndef CONFIG_USB_DEFAULT_PERSIST
39383937
/*
39393938
* We called pm_runtime_get_noresume when the device was attached.
39403939
* Decrement the counter here to allow controller to runtime suspend
39413940
* if no devices remain.
39423941
*/
39433942
if (xhci->quirks & XHCI_RESET_ON_RESUME)
39443943
pm_runtime_put_noidle(hcd->self.controller);
3945-
#endif
39463944

39473945
ret = xhci_check_args(hcd, udev, NULL, 0, true, __func__);
39483946
/* If the host is halted due to driver unload, we still need to free the
@@ -3961,9 +3959,8 @@ static void xhci_free_dev(struct usb_hcd *hcd, struct usb_device *udev)
39613959
del_timer_sync(&virt_dev->eps[i].stop_cmd_timer);
39623960
}
39633961
virt_dev->udev = NULL;
3964-
ret = xhci_disable_slot(xhci, udev->slot_id);
3965-
if (ret)
3966-
xhci_free_virt_device(xhci, udev->slot_id);
3962+
xhci_disable_slot(xhci, udev->slot_id);
3963+
xhci_free_virt_device(xhci, udev->slot_id);
39673964
}
39683965

39693966
int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id)
@@ -3973,7 +3970,7 @@ int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id)
39733970
u32 state;
39743971
int ret = 0;
39753972

3976-
command = xhci_alloc_command(xhci, false, GFP_KERNEL);
3973+
command = xhci_alloc_command(xhci, true, GFP_KERNEL);
39773974
if (!command)
39783975
return -ENOMEM;
39793976

@@ -3998,6 +3995,15 @@ int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id)
39983995
}
39993996
xhci_ring_cmd_db(xhci);
40003997
spin_unlock_irqrestore(&xhci->lock, flags);
3998+
3999+
wait_for_completion(command->completion);
4000+
4001+
if (command->status != COMP_SUCCESS)
4002+
xhci_warn(xhci, "Unsuccessful disable slot %u command, status %d\n",
4003+
slot_id, command->status);
4004+
4005+
xhci_free_command(xhci, command);
4006+
40014007
return ret;
40024008
}
40034009

@@ -4094,23 +4100,20 @@ int xhci_alloc_dev(struct usb_hcd *hcd, struct usb_device *udev)
40944100

40954101
xhci_debugfs_create_slot(xhci, slot_id);
40964102

4097-
#ifndef CONFIG_USB_DEFAULT_PERSIST
40984103
/*
40994104
* If resetting upon resume, we can't put the controller into runtime
41004105
* suspend if there is a device attached.
41014106
*/
41024107
if (xhci->quirks & XHCI_RESET_ON_RESUME)
41034108
pm_runtime_get_noresume(hcd->self.controller);
4104-
#endif
41054109

41064110
/* Is this a LS or FS device under a HS hub? */
41074111
/* Hub or peripherial? */
41084112
return 1;
41094113

41104114
disable_slot:
4111-
ret = xhci_disable_slot(xhci, udev->slot_id);
4112-
if (ret)
4113-
xhci_free_virt_device(xhci, udev->slot_id);
4115+
xhci_disable_slot(xhci, udev->slot_id);
4116+
xhci_free_virt_device(xhci, udev->slot_id);
41144117

41154118
return 0;
41164119
}
@@ -4240,6 +4243,7 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev,
42404243

42414244
mutex_unlock(&xhci->mutex);
42424245
ret = xhci_disable_slot(xhci, udev->slot_id);
4246+
xhci_free_virt_device(xhci, udev->slot_id);
42434247
if (!ret)
42444248
xhci_alloc_dev(hcd, udev);
42454249
kfree(command->completion);

0 commit comments

Comments
 (0)