[PATCH 4/4] thunderbolt: prevent pcie tunnel activation/teardown warnings
Mika Westerberg
mika.westerberg at linux.intel.com
Fri Oct 30 01:56:28 PDT 2026
On Fri, Oct 30, 2026 at 04:25:39PM +0800, Chunfeng Yun wrote:
> 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
It's router
> 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:
So this is runtime resume when there is no PCIe tunnel yet, the device is
unplugged and the userspace is at the same time writing to the "authorized"
attribute?
Then the PCIe tunnel creation fails as expected.
What warning you are trying to silence?
>
> The check prevents a redundant lookup and eliminates the warning
>
> Signed-off-by: Chunfeng Yun <chunfeng.yun at mediatek.com>
> ---
> 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
More information about the Linux-mediatek
mailing list