* [PATCH 0/3] xhci fixes for usb-linus
@ 2026-03-04 22:36 Mathias Nyman
2026-03-04 22:36 ` [PATCH 1/3] usb: xhci: Fix memory leak in xhci_disable_slot() Mathias Nyman
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: Mathias Nyman @ 2026-03-04 22:36 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
Three small fixes sorting out a memory leak, null pointer, and interrupt
storm triggered in rarely run error paths, or in debugfs reads
Thanks
Mathias
Dayu Jiang (1):
usb: xhci: Prevent interrupt storm on host controller error (HCE)
Mathias Nyman (1):
xhci: Fix NULL pointer dereference when reading portli debugfs files
Zilin Guan (1):
usb: xhci: Fix memory leak in xhci_disable_slot()
drivers/usb/host/xhci-debugfs.c | 10 +++++++++-
drivers/usb/host/xhci-ring.c | 1 +
drivers/usb/host/xhci.c | 4 ++--
3 files changed, 12 insertions(+), 3 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 1/3] usb: xhci: Fix memory leak in xhci_disable_slot()
2026-03-04 22:36 [PATCH 0/3] xhci fixes for usb-linus Mathias Nyman
@ 2026-03-04 22:36 ` Mathias Nyman
2026-03-04 22:36 ` [PATCH 2/3] usb: xhci: Prevent interrupt storm on host controller error (HCE) Mathias Nyman
2026-03-04 22:36 ` [PATCH 3/3] xhci: Fix NULL pointer dereference when reading portli debugfs files Mathias Nyman
2 siblings, 0 replies; 14+ messages in thread
From: Mathias Nyman @ 2026-03-04 22:36 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Zilin Guan, stable, Mathias Nyman
From: Zilin Guan <zilin@seu.edu.cn>
xhci_alloc_command() allocates a command structure and, when the
second argument is true, also allocates a completion structure.
Currently, the error handling path in xhci_disable_slot() only frees
the command structure using kfree(), causing the completion structure
to leak.
Use xhci_free_command() instead of kfree(). xhci_free_command() correctly
frees both the command structure and the associated completion structure.
Since the command structure is allocated with zero-initialization,
command->in_ctx is NULL and will not be erroneously freed by
xhci_free_command().
This bug was found using an experimental static analysis tool we are
developing. The tool is based on the LLVM framework and is specifically
designed to detect memory management issues. It is currently under
active development and not yet publicly available, but we plan to
open-source it after our research is published.
The bug was originally detected on v6.13-rc1 using our static analysis
tool, and we have verified that the issue persists in the latest mainline
kernel.
We performed build testing on x86_64 with allyesconfig using GCC=11.4.0.
Since triggering these error paths in xhci_disable_slot() requires specific
hardware conditions or abnormal state, we were unable to construct a test
case to reliably trigger these specific error paths at runtime.
Fixes: 7faac1953ed1 ("xhci: avoid race between disable slot command and host runtime suspend")
CC: stable@vger.kernel.org
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
drivers/usb/host/xhci.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index c36ab323d68e..ef6d8662adec 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -4146,7 +4146,7 @@ int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id)
if (state == 0xffffffff || (xhci->xhc_state & XHCI_STATE_DYING) ||
(xhci->xhc_state & XHCI_STATE_HALTED)) {
spin_unlock_irqrestore(&xhci->lock, flags);
- kfree(command);
+ xhci_free_command(xhci, command);
return -ENODEV;
}
@@ -4154,7 +4154,7 @@ int xhci_disable_slot(struct xhci_hcd *xhci, u32 slot_id)
slot_id);
if (ret) {
spin_unlock_irqrestore(&xhci->lock, flags);
- kfree(command);
+ xhci_free_command(xhci, command);
return ret;
}
xhci_ring_cmd_db(xhci);
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 2/3] usb: xhci: Prevent interrupt storm on host controller error (HCE)
2026-03-04 22:36 [PATCH 0/3] xhci fixes for usb-linus Mathias Nyman
2026-03-04 22:36 ` [PATCH 1/3] usb: xhci: Fix memory leak in xhci_disable_slot() Mathias Nyman
@ 2026-03-04 22:36 ` Mathias Nyman
2026-03-04 22:36 ` [PATCH 3/3] xhci: Fix NULL pointer dereference when reading portli debugfs files Mathias Nyman
2 siblings, 0 replies; 14+ messages in thread
From: Mathias Nyman @ 2026-03-04 22:36 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Dayu Jiang, stable, Mathias Nyman
From: Dayu Jiang <jiangdayu@xiaomi.com>
The xHCI controller reports a Host Controller Error (HCE) in UAS Storage
Device plug/unplug scenarios on Android devices. HCE is checked in
xhci_irq() function and causes an interrupt storm (since the interrupt
isn’t cleared), leading to severe system-level faults.
When the xHC controller reports HCE in the interrupt handler, the driver
only logs a warning and assumes xHC activity will stop as stated in xHCI
specification. An interrupt storm does however continue on some hosts
even after HCE, and only ceases after manually disabling xHC interrupt
and stopping the controller by calling xhci_halt().
Add xhci_halt() to xhci_irq() function where STS_HCE status is checked,
mirroring the existing error handling pattern used for STS_FATAL errors.
This only fixes the interrupt storm. Proper HCE recovery requires resetting
and re-initializing the xHC.
CC: stable@vger.kernel.org
Signed-off-by: Dayu Jiang <jiangdayu@xiaomi.com>
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
drivers/usb/host/xhci-ring.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 9315ba18310d..1cbefee3c4ca 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -3195,6 +3195,7 @@ irqreturn_t xhci_irq(struct usb_hcd *hcd)
if (status & STS_HCE) {
xhci_warn(xhci, "WARNING: Host Controller Error\n");
+ xhci_halt(xhci);
goto out;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread* [PATCH 3/3] xhci: Fix NULL pointer dereference when reading portli debugfs files
2026-03-04 22:36 [PATCH 0/3] xhci fixes for usb-linus Mathias Nyman
2026-03-04 22:36 ` [PATCH 1/3] usb: xhci: Fix memory leak in xhci_disable_slot() Mathias Nyman
2026-03-04 22:36 ` [PATCH 2/3] usb: xhci: Prevent interrupt storm on host controller error (HCE) Mathias Nyman
@ 2026-03-04 22:36 ` Mathias Nyman
2 siblings, 0 replies; 14+ messages in thread
From: Mathias Nyman @ 2026-03-04 22:36 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman, Michal Pecio, stable
Michal reported and debgged a NULL pointer dereference bug in the
recently added portli debugfs files
Oops is caused when there are more port registers counted in
xhci->max_ports than ports reported by Supported Protocol capabilities.
This is possible if max_ports is more than maximum port number, or
if there are gaps between ports of different speeds the 'Supported
Protocol' capabilities.
In such cases port->rhub will be NULL so we can't reach xhci behind it.
Add an explicit NULL check for this case, and print portli in hex
without dereferencing port->rhub.
Reported-by: Michal Pecio <michal.pecio@gmail.com>
Closes: https://lore.kernel.org/linux-usb/20260304103856.48b785fd.michal.pecio@gmail.com
Fixes: 384c57ec7205 ("usb: xhci: Add debugfs support for xHCI Port Link Info (PORTLI) register.")
Cc: stable@vger.kernel.org
Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com>
---
drivers/usb/host/xhci-debugfs.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/host/xhci-debugfs.c b/drivers/usb/host/xhci-debugfs.c
index 890fc5e892f1..ade178ab34a7 100644
--- a/drivers/usb/host/xhci-debugfs.c
+++ b/drivers/usb/host/xhci-debugfs.c
@@ -386,11 +386,19 @@ static const struct file_operations port_fops = {
static int xhci_portli_show(struct seq_file *s, void *unused)
{
struct xhci_port *port = s->private;
- struct xhci_hcd *xhci = hcd_to_xhci(port->rhub->hcd);
+ struct xhci_hcd *xhci;
u32 portli;
portli = readl(&port->port_reg->portli);
+ /* port without protocol capability isn't added to a roothub */
+ if (!port->rhub) {
+ seq_printf(s, "0x%08x\n", portli);
+ return 0;
+ }
+
+ xhci = hcd_to_xhci(port->rhub->hcd);
+
/* PORTLI fields are valid if port is a USB3 or eUSB2V2 port */
if (port->rhub == &xhci->usb3_rhub)
seq_printf(s, "0x%08x LEC=%u RLC=%u TLC=%u\n", portli,
--
2.43.0
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 0/3] xhci fixes for usb-linus
@ 2025-11-07 16:28 Mathias Nyman
0 siblings, 0 replies; 14+ messages in thread
From: Mathias Nyman @ 2025-11-07 16:28 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few more fixes for usb-linus 6.18-rc
Includes the xhci sideband locking fix and a DbC data corruption fix
Thanks
Mathias
Mathias Nyman (3):
xhci: fix stale flag preventig URBs after link state error is cleared
xhci: dbgtty: Fix data corruption when transmitting data form DbC to
host
xhci: sideband: Fix race condition in sideband unregister
drivers/usb/host/xhci-dbgcap.h | 1 +
drivers/usb/host/xhci-dbgtty.c | 17 +++++-
drivers/usb/host/xhci-ring.c | 15 +++--
drivers/usb/host/xhci-sideband.c | 102 ++++++++++++++++++-------------
drivers/usb/host/xhci.c | 1 +
5 files changed, 86 insertions(+), 50 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 0/3] xhci fixes for usb-linus
@ 2025-10-13 22:55 Mathias Nyman
0 siblings, 0 replies; 14+ messages in thread
From: Mathias Nyman @ 2025-10-13 22:55 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few fixes for usb-linus 6.18-rc
Solve an issue in the USB2 only PCI xHCI controller support added to 6.18
Solve two DbC cases that have been around since beginning of DbC support.
Thanks
Mathias
Mathias Nyman (2):
xhci: dbc: fix bogus 1024 byte prefix if ttyDBC read races with stall
event
xhci: dbc: enable back DbC in resume if it was enabled before suspend
Michal Pecio (1):
usb: xhci-pci: Fix USB2-only root hub registration
drivers/usb/host/xhci-dbgcap.c | 15 ++++++++++++---
drivers/usb/host/xhci-pci.c | 3 ++-
2 files changed, 14 insertions(+), 4 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 0/3] xhci fixes for usb-linus
@ 2025-09-02 10:53 Mathias Nyman
0 siblings, 0 replies; 14+ messages in thread
From: Mathias Nyman @ 2025-09-02 10:53 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A couple xhci fixes for usb-linus
Fixing a xhci memory leak regression in 6.17-rc3, and a DbC issue
triggered when re-connecting DbC cable ~10 times without data transfers
in between
Thanks
Mathias
Mathias Nyman (3):
xhci: dbc: decouple endpoint allocation from initialization
xhci: dbc: Fix full DbC transfer ring after several reconnects
xhci: fix memory leak regression when freeing xhci vdev devices depth
first
drivers/usb/host/xhci-dbgcap.c | 94 ++++++++++++++++++++++++----------
drivers/usb/host/xhci-mem.c | 2 +-
2 files changed, 68 insertions(+), 28 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 0/3] xhci fixes for usb-linus
@ 2023-03-30 14:30 Mathias Nyman
0 siblings, 0 replies; 14+ messages in thread
From: Mathias Nyman @ 2023-03-30 14:30 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few small patches for usb-linus.
Reverting xhci-pci asynchronous probe due to Renesas host regression, and
fixing a memory leak.
Thanks
Mathias
D Scott Phillips (1):
xhci: also avoid the XHCI_ZERO_64B_REGS quirk with a passthrough iommu
Mathias Nyman (2):
Revert "usb: xhci-pci: Set PROBE_PREFER_ASYNCHRONOUS"
xhci: Free the command allocated for setting LPM if we return early
drivers/usb/host/xhci-pci.c | 7 +++----
drivers/usb/host/xhci.c | 7 ++++++-
2 files changed, 9 insertions(+), 5 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 0/3] xhci fixes for usb-linus
@ 2022-08-25 15:08 Mathias Nyman
0 siblings, 0 replies; 14+ messages in thread
From: Mathias Nyman @ 2022-08-25 15:08 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few xhci fixes for usb-linus.
USB3 devices aren't visible immediately after xHC reset, so don't
stop polling the roothub and suspend too early after xHC reset.
Also Revert the port poweroff patch due to regression,
and fix a null pointer issue for xHC hosts with just one roothub.
-Mathias
Mathias Nyman (3):
xhci: Fix null pointer dereference in remove if xHC has only one
roothub
xhci: Add grace period after xHC start to prevent premature runtime
suspend.
Revert "xhci: turn off port power in shutdown"
drivers/usb/host/xhci-hub.c | 13 ++++++++++++-
drivers/usb/host/xhci-plat.c | 11 ++++++++---
drivers/usb/host/xhci.c | 19 +++++--------------
drivers/usb/host/xhci.h | 4 +---
4 files changed, 26 insertions(+), 21 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 0/3] xhci fixes for usb-linus
@ 2022-04-08 13:48 Mathias Nyman
0 siblings, 0 replies; 14+ messages in thread
From: Mathias Nyman @ 2022-04-08 13:48 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few small xhci fixes for usb-linus
Fixes USB 3 link resume for tunneled USB 3 devices, timers left running
after shutdown, and a bug in how we handle a full event ring.
Thanks
-Mathias
Henry Lin (1):
xhci: stop polling roothubs after shutdown
Mathias Nyman (1):
xhci: increase usb U3 -> U0 link resume timeout from 100ms to 500ms
Weitao Wang (1):
USB: Fix xhci event ring dequeue pointer ERDP update issue
drivers/usb/host/xhci-hub.c | 2 +-
drivers/usb/host/xhci-ring.c | 1 +
drivers/usb/host/xhci.c | 11 +++++++++++
3 files changed, 13 insertions(+), 1 deletion(-)
--
2.25.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 0/3] xhci fixes for usb-linus
@ 2020-10-28 20:31 Mathias Nyman
0 siblings, 0 replies; 14+ messages in thread
From: Mathias Nyman @ 2020-10-28 20:31 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few xhci patches for usb-linus, including a fix for the xhci lockdep
oops in 5.10-rc1
-Mathias
Colin Ian King (1):
xhci: Fix sizeof() mismatch
Mathias Nyman (1):
xhci: Don't create stream debugfs files with spinlock held.
Sandeep Singh (1):
usb: xhci: Workaround for S3 issue on AMD SNPS 3.0 xHC
drivers/usb/host/xhci-mem.c | 4 ++--
drivers/usb/host/xhci-pci.c | 17 +++++++++++++++++
drivers/usb/host/xhci.c | 5 ++++-
drivers/usb/host/xhci.h | 1 +
4 files changed, 24 insertions(+), 3 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 0/3] xhci fixes for usb-linus
@ 2020-08-21 9:15 Mathias Nyman
0 siblings, 0 replies; 14+ messages in thread
From: Mathias Nyman @ 2020-08-21 9:15 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few xhci fixes for usb-linus.
This series makes sure we don't ignore devices attached during suspend that
are stuck in a resume "cold attach status" state, and makes sure xhci driver
doesn't prevent queuing urbs to a endpoint only because driver previously
refused to manually clear the data toggle of a non-empty endpoint.
-Mathias
Ding Hui (1):
xhci: Always restore EP_SOFT_CLEAR_TOGGLE even if ep reset failed
Kai-Heng Feng (1):
xhci: Do warm-reset when both CAS and XDEV_RESUME are set
Li Jun (1):
usb: host: xhci: fix ep context print mismatch in debugfs
drivers/usb/host/xhci-debugfs.c | 8 ++++----
drivers/usb/host/xhci-hub.c | 19 ++++++++++---------
drivers/usb/host/xhci.c | 3 ++-
3 files changed, 16 insertions(+), 14 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 0/3] xhci fixes for usb-linus
@ 2020-04-21 14:08 Mathias Nyman
0 siblings, 0 replies; 14+ messages in thread
From: Mathias Nyman @ 2020-04-21 14:08 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
These xhci fixes for usb-linus sort out halted empty endpoint handling,
protocol stall handling, and overcurrent handling.
Theses issues have caused usb devices to appear as if they stop working
suddenly, failed to enumerate LS/FS devices behind HS hubs (seen on some
audio devices), and host from freezing in case of suspend on over-current.
-Mathias
Mathias Nyman (3):
xhci: Fix handling halted endpoint even if endpoint ring appears empty
xhci: prevent bus suspend if a roothub port detected a over-current
condition
xhci: Don't clear hub TT buffer on ep0 protocol stall
drivers/usb/host/xhci-hub.c | 9 +++++++
drivers/usb/host/xhci-ring.c | 46 +++++++++++++++++++++++++++++++-----
drivers/usb/host/xhci.c | 14 +++++------
drivers/usb/host/xhci.h | 5 ++--
4 files changed, 59 insertions(+), 15 deletions(-)
--
2.17.1
^ permalink raw reply [flat|nested] 14+ messages in thread* [PATCH 0/3] xhci fixes for usb-linus
@ 2019-10-25 14:30 Mathias Nyman
0 siblings, 0 replies; 14+ messages in thread
From: Mathias Nyman @ 2019-10-25 14:30 UTC (permalink / raw)
To: gregkh; +Cc: linux-usb, Mathias Nyman
Hi Greg
A few xhci fixes for usb-linus, solving a couple endianness issues, and a
use-after-free regression reported by Johan Hovold
-Mathias
Ben Dooks (Codethink) (1):
usb: xhci: fix __le32/__le64 accessors in debugfs code
Mathias Nyman (1):
xhci: Fix use-after-free regression in xhci clear hub TT
implementation
Samuel Holland (1):
usb: xhci: fix Immediate Data Transfer endianness
drivers/usb/host/xhci-debugfs.c | 24 +++++++++---------
drivers/usb/host/xhci-ring.c | 2 ++
drivers/usb/host/xhci.c | 54 ++++++++++++++++++++++++++++++++++-------
3 files changed, 59 insertions(+), 21 deletions(-)
--
2.7.4
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2026-03-04 22:36 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04 22:36 [PATCH 0/3] xhci fixes for usb-linus Mathias Nyman
2026-03-04 22:36 ` [PATCH 1/3] usb: xhci: Fix memory leak in xhci_disable_slot() Mathias Nyman
2026-03-04 22:36 ` [PATCH 2/3] usb: xhci: Prevent interrupt storm on host controller error (HCE) Mathias Nyman
2026-03-04 22:36 ` [PATCH 3/3] xhci: Fix NULL pointer dereference when reading portli debugfs files Mathias Nyman
-- strict thread matches above, loose matches on Subject: below --
2025-11-07 16:28 [PATCH 0/3] xhci fixes for usb-linus Mathias Nyman
2025-10-13 22:55 Mathias Nyman
2025-09-02 10:53 Mathias Nyman
2023-03-30 14:30 Mathias Nyman
2022-08-25 15:08 Mathias Nyman
2022-04-08 13:48 Mathias Nyman
2020-10-28 20:31 Mathias Nyman
2020-08-21 9:15 Mathias Nyman
2020-04-21 14:08 Mathias Nyman
2019-10-25 14:30 Mathias Nyman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox