This is a note to let you know that I've just added the patch titled thunderbolt: Fix memory leak in margining to the 6.2-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: thunderbolt-fix-memory-leak-in-margining.patch and it can be found in the queue-6.2 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From acec726473822bc6b585961f4ca2a11fa7f28341 Mon Sep 17 00:00:00 2001 From: Mika Westerberg <mika.westerberg@xxxxxxxxxxxxxxx> Date: Fri, 3 Mar 2023 11:25:08 +0200 Subject: thunderbolt: Fix memory leak in margining From: Mika Westerberg <mika.westerberg@xxxxxxxxxxxxxxx> commit acec726473822bc6b585961f4ca2a11fa7f28341 upstream. 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: d0f1e0c2a699 ("thunderbolt: Add support for receiver lane margining") Cc: stable@xxxxxxxxxxxxxxx Signed-off-by: Mika Westerberg <mika.westerberg@xxxxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/thunderbolt/debugfs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/drivers/thunderbolt/debugfs.c +++ b/drivers/thunderbolt/debugfs.c @@ -942,7 +942,8 @@ static void margining_port_remove(struct snprintf(dir_name, sizeof(dir_name), "port%d", port->port); parent = debugfs_lookup(dir_name, port->sw->debugfs_dir); - debugfs_remove_recursive(debugfs_lookup("margining", parent)); + if (parent) + debugfs_remove_recursive(debugfs_lookup("margining", parent)); kfree(port->usb4->margining); port->usb4->margining = NULL; @@ -967,19 +968,18 @@ static void margining_switch_init(struct 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); } Patches currently in stable-queue which might be from mika.westerberg@xxxxxxxxxxxxxxx are queue-6.2/thunderbolt-use-const-qualifier-for-ring_interrupt_index.patch queue-6.2/thunderbolt-add-quirk-to-disable-clx.patch queue-6.2/thunderbolt-rename-shadowed-variables-bit-to-interrupt_bit-and-auto_clear_bit.patch queue-6.2/thunderbolt-use-scale-field-when-allocating-usb3-bandwidth.patch queue-6.2/thunderbolt-disable-interrupt-auto-clear-for-rings.patch queue-6.2/thunderbolt-add-missing-unset_inbound_sbtx-for-retimer-access.patch queue-6.2/thunderbolt-fix-memory-leak-in-margining.patch queue-6.2/thunderbolt-call-tb_check_quirks-after-initializing-adapters.patch