[PATCH 01/11] NTB: ntb_transport: Remove the device debugfs directory

From: Koichiro Den

Date: Mon Sep 07 2026 - 10:25:09 EST


ntb_transport_free() removes QP debugfs directories but leaves the
device directory. On rebind, debugfs_create_dir() fails with -EEXIST
and QP statistics files are not recreated. Module unload masks this
by removing the entire debugfs tree.

To reproduce:

# ls /sys/kernel/debug/ntb_transport/0001:10:00.0/
qp0
# echo 0001:10:00.0 > /sys/bus/ntb/drivers/ntb_transport/unbind
# ls /sys/kernel/debug/ntb_transport/
0001:10:00.0 <-- should not remain
# echo 0001:10:00.0 > /sys/bus/ntb/drivers/ntb_transport/bind

.. and then dmesg shows:
debugfs: '0001:10:00.0' already exists in 'ntb_transport'

# ls /sys/kernel/debug/ntb_transport/0001:10:00.0/
(nothing) <-- should be 'qp0'

Remove the device debugfs tree on teardown and probe failure.

Verified that unbind removes the directory and rebind recreates qp0.

Fixes: c8650fd03d32 ("NTB: Fix transport stats for multiple devices")
Signed-off-by: Koichiro Den <den@xxxxxxxxxxxxx>
---
drivers/ntb/ntb_transport.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/ntb/ntb_transport.c b/drivers/ntb/ntb_transport.c
index f9caa1a653c5..3389d6ca9ebd 100644
--- a/drivers/ntb/ntb_transport.c
+++ b/drivers/ntb/ntb_transport.c
@@ -1382,6 +1382,7 @@ static int ntb_transport_probe(struct ntb_client *self, struct ntb_dev *ndev)
err3:
ntb_clear_ctx(ndev);
err2:
+ debugfs_remove_recursive(nt->debugfs_node_dir);
kfree(nt->qp_vec);
err1:
while (i--) {
@@ -1401,6 +1402,8 @@ static void ntb_transport_free(struct ntb_client *self, struct ntb_dev *ndev)
u64 qp_bitmap_alloc;
int i;

+ debugfs_remove_recursive(nt->debugfs_node_dir);
+
ntb_transport_link_cleanup(nt);
cancel_work_sync(&nt->link_cleanup);
cancel_delayed_work_sync(&nt->link_work);
@@ -1412,7 +1415,6 @@ static void ntb_transport_free(struct ntb_client *self, struct ntb_dev *ndev)
qp = &nt->qp_vec[i];
if (qp_bitmap_alloc & BIT_ULL(i))
ntb_transport_free_queue(qp);
- debugfs_remove_recursive(qp->debugfs_dir);
}

ntb_link_disable(ndev);
--
2.51.0