Skip to content

Commit acec726

Browse files
committed
thunderbolt: Fix memory leak in margining
Memory for the usb4->margining needs to be relased for the upstream port of the router as well, even though the debugfs directory gets released with the router device removal. Fix this. Fixes: d0f1e0c ("thunderbolt: Add support for receiver lane margining") Cc: [email protected] Signed-off-by: Mika Westerberg <[email protected]>
1 parent 7af9da8 commit acec726

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

drivers/thunderbolt/debugfs.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,8 @@ static void margining_port_remove(struct tb_port *port)
942942

943943
snprintf(dir_name, sizeof(dir_name), "port%d", port->port);
944944
parent = debugfs_lookup(dir_name, port->sw->debugfs_dir);
945-
debugfs_remove_recursive(debugfs_lookup("margining", parent));
945+
if (parent)
946+
debugfs_remove_recursive(debugfs_lookup("margining", parent));
946947

947948
kfree(port->usb4->margining);
948949
port->usb4->margining = NULL;
@@ -967,19 +968,18 @@ static void margining_switch_init(struct tb_switch *sw)
967968

968969
static void margining_switch_remove(struct tb_switch *sw)
969970
{
971+
struct tb_port *upstream, *downstream;
970972
struct tb_switch *parent_sw;
971-
struct tb_port *downstream;
972973
u64 route = tb_route(sw);
973974

974975
if (!route)
975976
return;
976977

977-
/*
978-
* Upstream is removed with the router itself but we need to
979-
* remove the downstream port margining directory.
980-
*/
978+
upstream = tb_upstream_port(sw);
981979
parent_sw = tb_switch_parent(sw);
982980
downstream = tb_port_at(route, parent_sw);
981+
982+
margining_port_remove(upstream);
983983
margining_port_remove(downstream);
984984
}
985985

0 commit comments

Comments
 (0)