[PATCH 4/4] thunderbolt: prevent pcie tunnel activation/teardown warnings
From: Chunfeng Yun
Date: Fri Oct 30 2026 - 04:31:33 EST
When usb4 enter sleep mode, echo 1 to authorized of sysfile,
will wakeup usb4 driver, but fail to create pcie tunnel, cause
the warning due to a race condition between switch disconnect
during resume and user authorization
When usb4 enter sleep mode, echo 0 to authorized of sysfile,
will wakeup usb4 driver, but fail to disconnect pcie due to
the PCIe tunnel had already been torn down and freed if the port
is fail to resume:
The check prevents a redundant lookup and eliminates the warning
Signed-off-by: Chunfeng Yun <chunfeng.yun@xxxxxxxxxxxx>
---
drivers/thunderbolt/switch.c | 5 +++++
drivers/thunderbolt/tb.c | 7 +++++++
2 files changed, 12 insertions(+)
diff --git a/drivers/thunderbolt/switch.c b/drivers/thunderbolt/switch.c
index e7ee9639c54c..7902172f4e99 100644
--- a/drivers/thunderbolt/switch.c
+++ b/drivers/thunderbolt/switch.c
@@ -1849,6 +1849,11 @@ static int tb_switch_set_authorized(struct tb_switch *sw, unsigned int val)
if (!!sw->authorized == !!val)
goto unlock;
+ if (sw->is_unplugged) {
+ ret = -ENODEV;
+ goto unlock;
+ }
+
switch (val) {
/* Disapprove switch */
case 0:
diff --git a/drivers/thunderbolt/tb.c b/drivers/thunderbolt/tb.c
index 57c11ba13459..69310622d786 100644
--- a/drivers/thunderbolt/tb.c
+++ b/drivers/thunderbolt/tb.c
@@ -2266,6 +2266,10 @@ static int tb_disconnect_pci(struct tb *tb, struct tb_switch *sw)
struct tb_tunnel *tunnel;
struct tb_port *up;
+ /* If the switch has already been unplugged, tunnels are already freed */
+ if (sw->is_unplugged)
+ return 0;
+
up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP);
if (WARN_ON(!up))
return -ENODEV;
@@ -2288,6 +2292,9 @@ static int tb_tunnel_pci(struct tb *tb, struct tb_switch *sw)
struct tb_cm *tcm = tb_priv(tb);
struct tb_tunnel *tunnel;
+ if (sw->is_unplugged)
+ return -ENODEV;
+
up = tb_switch_find_port(sw, TB_TYPE_PCIE_UP);
if (!up)
return 0;
--
2.43.0