[PATCH v4 05/14] thunderbolt: Move rpm_complete bus walk to domain.c

From: Chunfeng Yun

Date: Sat Dec 05 2026 - 03:34:46 EST


Currently, remove_unplugged_switch() in icm.c traverses all devices on
the bus using bus_for_each_dev(&tb_bus_type, ...) to signal rpm_complete
before calling tb_switch_remove().

This creates a direct dependency on the internal struct bus_type
tb_bus_type in icm.c. When icm.c is modularized, this would require
exporting tb_bus_type to other modules, leaking subsystem core internals.

Encapsulate this bus traversal inside domain.c as tb_domain_complete_rpm().
This keeps tb_bus_type private to domain.c and eliminates the need to
export the bus structure.

Signed-off-by: Chunfeng Yun <chunfeng.yun@xxxxxxxxxxxx>
---
new patch
---
drivers/thunderbolt/domain.c | 24 ++++++++++++++++++++++++
drivers/thunderbolt/icm.c | 17 +----------------
drivers/thunderbolt/tb.h | 1 +
3 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/drivers/thunderbolt/domain.c b/drivers/thunderbolt/domain.c
index 24611f05b3cd..075e0f8af1e8 100644
--- a/drivers/thunderbolt/domain.c
+++ b/drivers/thunderbolt/domain.c
@@ -881,6 +881,30 @@ int tb_domain_unregister_unplugged_xdomains(struct tb *tb)
return ctx.n;
}

+static int complete_rpm(struct device *dev, void *data)
+{
+ struct tb_switch *sw = tb_to_switch(dev);
+
+ if (sw && sw->tb == data)
+ complete(&sw->rpm_complete);
+
+ return 0;
+}
+
+/**
+ * tb_domain_complete_rpm() - Signal runtime resume completion for router and below
+ * @tb: Domain the router belongs to
+ * @sw: Router to complete runtime resume
+ *
+ * Signal @sw and routers below for rpm_complete because
+ * tb_switch_remove() calls pm_runtime_get_sync() that then waits for it.
+ */
+void tb_domain_complete_rpm(struct tb *tb, struct tb_switch *sw)
+{
+ complete_rpm(&sw->dev, tb);
+ bus_for_each_dev(&tb_bus_type, &sw->dev, tb, complete_rpm);
+}
+
int tb_domain_init(void)
{
int ret;
diff --git a/drivers/thunderbolt/icm.c b/drivers/thunderbolt/icm.c
index a295a5e6cc9c..f2c387d226f0 100644
--- a/drivers/thunderbolt/icm.c
+++ b/drivers/thunderbolt/icm.c
@@ -2068,28 +2068,13 @@ static void icm_unplug_children(struct tb_switch *sw)
}
}

-static int complete_rpm(struct device *dev, void *data)
-{
- struct tb_switch *sw = tb_to_switch(dev);
-
- if (sw && sw->tb == data)
- complete(&sw->rpm_complete);
- return 0;
-}
-
static void remove_unplugged_switch(struct tb_switch *sw)
{
struct device *parent = get_device(sw->dev.parent);

pm_runtime_get_sync(parent);

- /*
- * Signal this and switches below for rpm_complete because
- * tb_switch_remove() calls pm_runtime_get_sync() that then waits
- * for it.
- */
- complete_rpm(&sw->dev, sw->tb);
- bus_for_each_dev(&tb_bus_type, &sw->dev, sw->tb, complete_rpm);
+ tb_domain_complete_rpm(sw->tb, sw);
tb_switch_remove(sw);

pm_runtime_mark_last_busy(parent);
diff --git a/drivers/thunderbolt/tb.h b/drivers/thunderbolt/tb.h
index 9158b8f3580f..d6c188922ca1 100644
--- a/drivers/thunderbolt/tb.h
+++ b/drivers/thunderbolt/tb.h
@@ -797,6 +797,7 @@ int tb_domain_disconnect_xdomain_paths(struct tb *tb, struct tb_xdomain *xd,
int receive_path, int receive_ring);
int tb_domain_disconnect_all_paths(struct tb *tb);
int tb_domain_unregister_unplugged_xdomains(struct tb *tb);
+void tb_domain_complete_rpm(struct tb *tb, struct tb_switch *sw);

static inline struct tb *tb_domain_get(struct tb *tb)
{
--
2.45.2