Commit acec7264 authored by Mika Westerberg's avatar Mika Westerberg
Browse files

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: d0f1e0c2 ("thunderbolt: Add support for receiver lane margining")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
parent 7af9da8c
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -942,6 +942,7 @@ static void margining_port_remove(struct tb_port *port)

	snprintf(dir_name, sizeof(dir_name), "port%d", port->port);
	parent = debugfs_lookup(dir_name, port->sw->debugfs_dir);
	if (parent)
		debugfs_remove_recursive(debugfs_lookup("margining", parent));

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

static void margining_switch_remove(struct tb_switch *sw)
{
	struct tb_port *upstream, *downstream;
	struct tb_switch *parent_sw;
	struct tb_port *downstream;
	u64 route = tb_route(sw);

	if (!route)
		return;

	/*
	 * Upstream is removed with the router itself but we need to
	 * remove the downstream port margining directory.
	 */
	upstream = tb_upstream_port(sw);
	parent_sw = tb_switch_parent(sw);
	downstream = tb_port_at(route, parent_sw);

	margining_port_remove(upstream);
	margining_port_remove(downstream);
}