Skip to contentSkip to conversation

xhci fixes for usb-linus

PATCH New Mathias Nyman 1 participant 3 messages Aug 9, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover xhci fixes for usb-linus

Hi Greg

A couple small fixes for 6.11-rc

- Don't try to free interrupters that failed to allocate.

- Add missing "return 0" lost in refactoring of tranfer event handler, this causes extra unneeded check for halted endpoint handling.

Thanks
Mathias

Marc Zyngier (1):
usb: xhci: Check for xhci->interrupters being allocated in
xhci_mem_clearup()

Niklas Neronin (1):
usb: xhci: fix duplicate stall handling in handle_tx_event()

 drivers/usb/host/xhci-mem.c  | 2 +-
 drivers/usb/host/xhci-ring.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 usb: xhci: Check for xhci->interrupters being allocated in xhci_mem_clearup()

From: Marc Zyngier <[email protected]>

If xhci_mem_init() fails, it calls into xhci_mem_cleanup() to mop up the damage. If it fails early enough, before xhci->interrupters is allocated but after xhci->max_interrupters has been set, which happens in most (all?) cases, things get uglier, as xhci_mem_cleanup() unconditionally derefences xhci->interrupters. With prejudice.

Gate the interrupt freeing loop with a check on xhci->interrupters being non-NULL.

Found while debugging a DMA allocation issue that led the XHCI driver on this exact path.

Fixes c99b38c41234 ("xhci: add support to allocate several interrupters")
Cc Mathias Nyman <[email protected]>
Cc Wesley Cheng <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
---
 drivers/usb/host/xhci-mem.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/host/xhci-mem.c +1 -1
index d7654f475daf..937ce5fd5809 100644
@@ -1872,7 +1872,7 @@ void xhci_mem_cleanup(struct xhci_hcd *xhci)
 
 	cancel_delayed_work_sync(&xhci->cmd_timer);
 
-	for (i = 0; i < xhci->max_interrupters; i++) {
+	for (i = 0; xhci->interrupters && i < xhci->max_interrupters; i++) {
 		if (xhci->interrupters[i]) {
 			xhci_remove_interrupter(xhci, xhci->interrupters[i]);
 			xhci_free_interrupter(xhci, xhci->interrupters[i]);
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/2 usb: xhci: fix duplicate stall handling in handle_tx_event()

In reply to Mathias Nyman

From: Niklas Neronin <[email protected]>

Stall handling is managed in the 'process_*' functions, which are called right before the 'goto' stall handling code snippet. Thus, there should be a return after the 'process_*' functions. Otherwise, the stall code may run twice.

Fixes 1b349f214ac7 ("usb: xhci: add 'goto' for halted endpoint check in handle_tx_event()")
---
 drivers/usb/host/xhci-ring.c | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/host/xhci-ring.c +1 -0
index b7517c3c8059..4ea2c3e072a9 100644
@@ -2910,6 +2910,7 @@ static int handle_tx_event(struct xhci_hcd *xhci,
 		process_isoc_td(xhci, ep, ep_ring, td, ep_trb, event);
 	else
 		process_bulk_intr_td(xhci, ep, ep_ring, td, ep_trb, event);
+	return 0;
 
 check_endpoint_halted:
 	if (xhci_halted_host_endpoint(ep_ctx, trb_comp_code))
Signature · 1 line
2.25.1