Skip to content

Commit 523d0b1

Browse files
committed
Merge tag 'usb-5.13-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
Pull USB / Thunderbolt fixes from Greg KH: "Here are a number of tiny USB and Thunderbolt driver fixes for 5.13-rc4. They consist of: - thunderbolt fixes for some NVM bound issues - xhci fixes for reported problems - control-request fixups - documentation build warning fixes - new usb-serial driver device ids - typec bugfixes for reported issues - usbfs warning fixups (could be triggered from userspace) - other tiny fixes for reported problems. All of these have been in linux-next with no reported issues" * tag 'usb-5.13-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb: (22 commits) xhci: Fix 5.12 regression of missing xHC cache clearing command after a Stall xhci: fix giving back URB with incorrect status regression in 5.12 usb: gadget: udc: renesas_usb3: Fix a race in usb3_start_pipen() usb: typec: tcpm: Respond Not_Supported if no snk_vdo usb: typec: tcpm: Properly interrupt VDM AMS USB: trancevibrator: fix control-request direction usb: Restore the usb_header label usb: typec: tcpm: Use LE to CPU conversion when accessing msg->header usb: typec: ucsi: Clear pending after acking connector change usb: typec: mux: Fix matching with typec_altmode_desc misc/uss720: fix memory leak in uss720_probe usb: dwc3: gadget: Properly track pending and queued SG USB: usbfs: Don't WARN about excessively large memory allocations thunderbolt: usb4: Fix NVM read buffer bounds and offset issue thunderbolt: dma_port: Fix NVM read buffer bounds and offset issue usb: chipidea: udc: assign interrupt number to USB gadget structure usb: cdnsp: Fix lack of removing request from pending list. usb: cdns3: Fix runtime PM imbalance on error USB: serial: pl2303: add device id for ADLINK ND-6530 GC USB: serial: ti_usb_3410_5052: add startech.com device id ...
2 parents 2244782 + a7f2e92 commit 523d0b1

File tree

21 files changed

+112
-44
lines changed

21 files changed

+112
-44
lines changed

Documentation/driver-api/usb/usb.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ are in ``drivers/usb/common/common.c``.
123123
In addition, some functions useful for creating debugging output are
124124
defined in ``drivers/usb/common/debug.c``.
125125

126+
.. _usb_header:
127+
126128
Host-Side Data Types and Macros
127129
===============================
128130

drivers/thunderbolt/dma_port.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,15 @@ int dma_port_flash_read(struct tb_dma_port *dma, unsigned int address,
366366
void *buf, size_t size)
367367
{
368368
unsigned int retries = DMA_PORT_RETRIES;
369-
unsigned int offset;
370-
371-
offset = address & 3;
372-
address = address & ~3;
373369

374370
do {
375-
u32 nbytes = min_t(u32, size, MAIL_DATA_DWORDS * 4);
371+
unsigned int offset;
372+
size_t nbytes;
376373
int ret;
377374

375+
offset = address & 3;
376+
nbytes = min_t(size_t, size + offset, MAIL_DATA_DWORDS * 4);
377+
378378
ret = dma_port_flash_read_block(dma, address, dma->buf,
379379
ALIGN(nbytes, 4));
380380
if (ret) {
@@ -386,6 +386,7 @@ int dma_port_flash_read(struct tb_dma_port *dma, unsigned int address,
386386
return ret;
387387
}
388388

389+
nbytes -= offset;
389390
memcpy(buf, dma->buf + offset, nbytes);
390391

391392
size -= nbytes;

drivers/thunderbolt/usb4.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ static int usb4_do_read_data(u16 address, void *buf, size_t size,
6868
unsigned int retries = USB4_DATA_RETRIES;
6969
unsigned int offset;
7070

71-
offset = address & 3;
72-
address = address & ~3;
73-
7471
do {
75-
size_t nbytes = min_t(size_t, size, USB4_DATA_DWORDS * 4);
7672
unsigned int dwaddress, dwords;
7773
u8 data[USB4_DATA_DWORDS * 4];
74+
size_t nbytes;
7875
int ret;
7976

77+
offset = address & 3;
78+
nbytes = min_t(size_t, size + offset, USB4_DATA_DWORDS * 4);
79+
8080
dwaddress = address / 4;
8181
dwords = ALIGN(nbytes, 4) / 4;
8282

@@ -87,6 +87,7 @@ static int usb4_do_read_data(u16 address, void *buf, size_t size,
8787
return ret;
8888
}
8989

90+
nbytes -= offset;
9091
memcpy(buf, data + offset, nbytes);
9192

9293
size -= nbytes;

drivers/usb/cdns3/cdns3-gadget.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3268,8 +3268,10 @@ static int __cdns3_gadget_init(struct cdns *cdns)
32683268
pm_runtime_get_sync(cdns->dev);
32693269

32703270
ret = cdns3_gadget_start(cdns);
3271-
if (ret)
3271+
if (ret) {
3272+
pm_runtime_put_sync(cdns->dev);
32723273
return ret;
3274+
}
32733275

32743276
/*
32753277
* Because interrupt line can be shared with other components in

drivers/usb/cdns3/cdnsp-gadget.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,17 +422,17 @@ int cdnsp_ep_enqueue(struct cdnsp_ep *pep, struct cdnsp_request *preq)
422422
int cdnsp_ep_dequeue(struct cdnsp_ep *pep, struct cdnsp_request *preq)
423423
{
424424
struct cdnsp_device *pdev = pep->pdev;
425-
int ret;
425+
int ret_stop = 0;
426+
int ret_rem;
426427

427428
trace_cdnsp_request_dequeue(preq);
428429

429-
if (GET_EP_CTX_STATE(pep->out_ctx) == EP_STATE_RUNNING) {
430-
ret = cdnsp_cmd_stop_ep(pdev, pep);
431-
if (ret)
432-
return ret;
433-
}
430+
if (GET_EP_CTX_STATE(pep->out_ctx) == EP_STATE_RUNNING)
431+
ret_stop = cdnsp_cmd_stop_ep(pdev, pep);
432+
433+
ret_rem = cdnsp_remove_request(pdev, preq, pep);
434434

435-
return cdnsp_remove_request(pdev, preq, pep);
435+
return ret_rem ? ret_rem : ret_stop;
436436
}
437437

438438
static void cdnsp_zero_in_ctx(struct cdnsp_device *pdev)

drivers/usb/chipidea/udc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,6 +2061,7 @@ static int udc_start(struct ci_hdrc *ci)
20612061
ci->gadget.name = ci->platdata->name;
20622062
ci->gadget.otg_caps = otg_caps;
20632063
ci->gadget.sg_supported = 1;
2064+
ci->gadget.irq = ci->irq;
20642065

20652066
if (ci->platdata->flags & CI_HDRC_REQUIRES_ALIGNED_DMA)
20662067
ci->gadget.quirk_avoids_skb_reserve = 1;

drivers/usb/core/devio.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,12 @@ static int do_proc_bulk(struct usb_dev_state *ps,
12181218
ret = usbfs_increase_memory_usage(len1 + sizeof(struct urb));
12191219
if (ret)
12201220
return ret;
1221-
tbuf = kmalloc(len1, GFP_KERNEL);
1221+
1222+
/*
1223+
* len1 can be almost arbitrarily large. Don't WARN if it's
1224+
* too big, just fail the request.
1225+
*/
1226+
tbuf = kmalloc(len1, GFP_KERNEL | __GFP_NOWARN);
12221227
if (!tbuf) {
12231228
ret = -ENOMEM;
12241229
goto done;
@@ -1696,7 +1701,7 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
16961701
if (num_sgs) {
16971702
as->urb->sg = kmalloc_array(num_sgs,
16981703
sizeof(struct scatterlist),
1699-
GFP_KERNEL);
1704+
GFP_KERNEL | __GFP_NOWARN);
17001705
if (!as->urb->sg) {
17011706
ret = -ENOMEM;
17021707
goto error;
@@ -1731,7 +1736,7 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
17311736
(uurb_start - as->usbm->vm_start);
17321737
} else {
17331738
as->urb->transfer_buffer = kmalloc(uurb->buffer_length,
1734-
GFP_KERNEL);
1739+
GFP_KERNEL | __GFP_NOWARN);
17351740
if (!as->urb->transfer_buffer) {
17361741
ret = -ENOMEM;
17371742
goto error;

drivers/usb/dwc3/gadget.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,14 +1244,15 @@ static int dwc3_prepare_trbs_sg(struct dwc3_ep *dep,
12441244
req->start_sg = sg_next(s);
12451245

12461246
req->num_queued_sgs++;
1247+
req->num_pending_sgs--;
12471248

12481249
/*
12491250
* The number of pending SG entries may not correspond to the
12501251
* number of mapped SG entries. If all the data are queued, then
12511252
* don't include unused SG entries.
12521253
*/
12531254
if (length == 0) {
1254-
req->num_pending_sgs -= req->request.num_mapped_sgs - req->num_queued_sgs;
1255+
req->num_pending_sgs = 0;
12551256
break;
12561257
}
12571258

@@ -2873,15 +2874,15 @@ static int dwc3_gadget_ep_reclaim_trb_sg(struct dwc3_ep *dep,
28732874
struct dwc3_trb *trb = &dep->trb_pool[dep->trb_dequeue];
28742875
struct scatterlist *sg = req->sg;
28752876
struct scatterlist *s;
2876-
unsigned int pending = req->num_pending_sgs;
2877+
unsigned int num_queued = req->num_queued_sgs;
28772878
unsigned int i;
28782879
int ret = 0;
28792880

2880-
for_each_sg(sg, s, pending, i) {
2881+
for_each_sg(sg, s, num_queued, i) {
28812882
trb = &dep->trb_pool[dep->trb_dequeue];
28822883

28832884
req->sg = sg_next(s);
2884-
req->num_pending_sgs--;
2885+
req->num_queued_sgs--;
28852886

28862887
ret = dwc3_gadget_ep_reclaim_completed_trb(dep, req,
28872888
trb, event, status, true);
@@ -2904,7 +2905,7 @@ static int dwc3_gadget_ep_reclaim_trb_linear(struct dwc3_ep *dep,
29042905

29052906
static bool dwc3_gadget_ep_request_completed(struct dwc3_request *req)
29062907
{
2907-
return req->num_pending_sgs == 0;
2908+
return req->num_pending_sgs == 0 && req->num_queued_sgs == 0;
29082909
}
29092910

29102911
static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep,
@@ -2913,7 +2914,7 @@ static int dwc3_gadget_ep_cleanup_completed_request(struct dwc3_ep *dep,
29132914
{
29142915
int ret;
29152916

2916-
if (req->num_pending_sgs)
2917+
if (req->request.num_mapped_sgs)
29172918
ret = dwc3_gadget_ep_reclaim_trb_sg(dep, req, event,
29182919
status);
29192920
else

drivers/usb/gadget/udc/renesas_usb3.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,15 +1488,16 @@ static void usb3_start_pipen(struct renesas_usb3_ep *usb3_ep,
14881488
struct renesas_usb3_request *usb3_req)
14891489
{
14901490
struct renesas_usb3 *usb3 = usb3_ep_to_usb3(usb3_ep);
1491-
struct renesas_usb3_request *usb3_req_first = usb3_get_request(usb3_ep);
1491+
struct renesas_usb3_request *usb3_req_first;
14921492
unsigned long flags;
14931493
int ret = -EAGAIN;
14941494
u32 enable_bits = 0;
14951495

14961496
spin_lock_irqsave(&usb3->lock, flags);
14971497
if (usb3_ep->halt || usb3_ep->started)
14981498
goto out;
1499-
if (usb3_req != usb3_req_first)
1499+
usb3_req_first = __usb3_get_request(usb3_ep);
1500+
if (!usb3_req_first || usb3_req != usb3_req_first)
15001501
goto out;
15011502

15021503
if (usb3_pn_change(usb3, usb3_ep->num) < 0)

drivers/usb/host/xhci-ring.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -828,14 +828,10 @@ static void xhci_giveback_invalidated_tds(struct xhci_virt_ep *ep)
828828
list_for_each_entry_safe(td, tmp_td, &ep->cancelled_td_list,
829829
cancelled_td_list) {
830830

831-
/*
832-
* Doesn't matter what we pass for status, since the core will
833-
* just overwrite it (because the URB has been unlinked).
834-
*/
835831
ring = xhci_urb_to_transfer_ring(ep->xhci, td->urb);
836832

837833
if (td->cancel_status == TD_CLEARED)
838-
xhci_td_cleanup(ep->xhci, td, ring, 0);
834+
xhci_td_cleanup(ep->xhci, td, ring, td->status);
839835

840836
if (ep->xhci->xhc_state & XHCI_STATE_DYING)
841837
return;
@@ -937,14 +933,18 @@ static int xhci_invalidate_cancelled_tds(struct xhci_virt_ep *ep)
937933
continue;
938934
}
939935
/*
940-
* If ring stopped on the TD we need to cancel, then we have to
936+
* If a ring stopped on the TD we need to cancel then we have to
941937
* move the xHC endpoint ring dequeue pointer past this TD.
938+
* Rings halted due to STALL may show hw_deq is past the stalled
939+
* TD, but still require a set TR Deq command to flush xHC cache.
942940
*/
943941
hw_deq = xhci_get_hw_deq(xhci, ep->vdev, ep->ep_index,
944942
td->urb->stream_id);
945943
hw_deq &= ~0xf;
946944

947-
if (trb_in_td(xhci, td->start_seg, td->first_trb,
945+
if (td->cancel_status == TD_HALTED) {
946+
cached_td = td;
947+
} else if (trb_in_td(xhci, td->start_seg, td->first_trb,
948948
td->last_trb, hw_deq, false)) {
949949
switch (td->cancel_status) {
950950
case TD_CLEARED: /* TD is already no-op */

0 commit comments

Comments
 (0)