[PATCH net v3 1/2] net: thunderbolt: Release the Rx HopID that was handed out on mismatch

Fan Ye via B4 Relay <[email protected]>
Newsgroups org.kernel.vger.netdev,org.kernel.feeds.b4-sent,org.kernel.vger.linux-kernel,org.kernel.vger.stable
Message-ID <[email protected]>
From: Fan Ye <[email protected]>

tb_xdomain_alloc_in_hopid() passes the wanted HopID to ida_alloc_range()
as the lower bound, so a taken id is not an error there: the allocator
returns the next free one above it. tbnet_connected_work() asks for the
peer's transmit path, treats any other id as a failure and returns
without releasing what it got, so that allocation stays live for the rest
of the XDomain connection with nothing left holding a reference to it.

Release the id when it is not the one we asked for, the same way the
error unwind at the end of the function releases the expected one.

Fixes: 180b0689425c ("thunderbolt: Allow multiple DMA tunnels over a single XDomain connection")
Cc: [email protected]
Assisted-by: Claude:claude-opus-5
Signed-off-by: Fan Ye <[email protected]>
Acked-by: Mika Westerberg <[email protected]>
---
Reached without fault injection on an ASMedia ASM4242 host-to-host link
when the peer drops out mid bring-up: 23 times across two hosts in one
run of interface down/up cycling. Each one ended in the XDomain
connection being rebuilt, which recreates the ida and disposes of the
leaked id, so what I am claiming here is the leak, not a symptom.

Patch 2/2 edits the lines this one adds and will not apply without it.

v3:
- Rewrote the commit message; dropped the quoted source and probe output.

v2: https://lore.kernel.org/netdev/[email protected]/
---
 drivers/net/thunderbolt/main.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/thunderbolt/main.c b/drivers/net/thunderbolt/main.c
index 98893732bc6e..e5199a87ea7a 100644
--- a/drivers/net/thunderbolt/main.c
+++ b/drivers/net/thunderbolt/main.c
@@ -647,6 +647,8 @@ static void tbnet_connected_work(struct work_struct *work)
 	ret = tb_xdomain_alloc_in_hopid(net->xd, net->remote_transmit_path);
 	if (ret != net->remote_transmit_path) {
 		netdev_err(net->dev, "failed to allocate Rx HopID\n");
+		if (ret >= 0)
+			tb_xdomain_release_in_hopid(net->xd, ret);
 		return;
 	}
 

-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.