[PATCH v3 8/8] thunderbolt: Drop WARN_ON() in tb_disconnect_pci()

From: Chunfeng Yun

Date: Mon Nov 23 2026 - 06:38:13 EST


tb_disconnect_pci() uses WARN_ON() if the upstream PCIe adapter port
or the associated PCIe tunnel cannot be found. This triggers a full
kernel stack trace in dmesg.

However, tb_disconnect_pci() is invoked when userspace deauthorizes
a router via sysfs (writing 0 to 'authorized'). Under dynamic runtime
conditions, an upstream port or active tunnel may not exist.
For example:
- If a USB4 router fails to resume or is unplugged during system/link
sleep, the disconnect flow may tear down and free the PCIe tunnel
before userspace deauthorization runs.
- If PCIe tunnel activation previously failed (e.g., due to link
training or Type-C handshake hiccups), the tunnel was never
established in the first place.

it seems unnecessary due to it does not indicate a kernel bug.
Furthermore, it causes unnecessary kernel panics on systems
booted with panic_on_warn.

Since -ENODEV is already returned to notify callers, simply drop the
WARN_ON() checks while keeping the -ENODEV return.

Signed-off-by: Chunfeng Yun <chunfeng.yun@xxxxxxxxxxxx>
---
v3:
* modify commit message.
* Reworked sw->is_unplugged checks to directly drop the WARN_ON(!up)
and WARN_ON(!tunnel) checks in tb_disconnect_pci()

v2: no changes
---
drivers/thunderbolt/tb.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index 57c11ba13459..5f674c305d43 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -2267,11 +2267,11 @@ static int tb_disconnect_pci(struct tb *tb, struct tb_switch *sw)
struct tb_port *up;

up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP);
- if (WARN_ON(!up))
+ if (!up)
return -ENODEV;

tunnel = tb_find_tunnel(tb, TB_TUNNEL_PCI, NULL, up);
- if (WARN_ON(!tunnel))
+ if (!tunnel)
return -ENODEV;

tb_switch_xhci_disconnect(sw);
--
2.45.2