[PATCH v2 1/3] dmaengine: of: Add managed DMA router registration

From: Tian Xuechen

Date: Fri Nov 27 2026 - 06:04:22 EST


Add devm_of_dma_router_register() to unregister a router when its
device is detached. Reuse the controller cleanup action, since routers
share the same OF registry. If registering the cleanup action fails,
remove the newly registered router immediately.

Signed-off-by: Tian Xuechen <202300460064@xxxxxxxxxxxxxxx>
---
Changes in v2:
- Add the reusable managed router helper.

include/linux/of_dma.h | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)

diff --git a/include/linux/of_dma.h b/include/linux/of_dma.h
index 16b08234d03b..7f9198ea9627 100644
--- a/include/linux/of_dma.h
+++ b/include/linux/of_dma.h
@@ -64,6 +64,21 @@ extern int of_dma_router_register(struct device_node *np,
struct dma_router *dma_router);
#define of_dma_router_free of_dma_controller_free

+static inline int
+devm_of_dma_router_register(struct device *dev, struct device_node *np,
+ void *(*of_dma_route_allocate)
+ (struct of_phandle_args *, struct of_dma *),
+ struct dma_router *dma_router)
+{
+ int ret;
+
+ ret = of_dma_router_register(np, of_dma_route_allocate, dma_router);
+ if (ret)
+ return ret;
+
+ return devm_add_action_or_reset(dev, __of_dma_controller_free, np);
+}
+
extern struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
const char *name);
extern struct dma_chan *of_dma_simple_xlate(struct of_phandle_args *dma_spec,
@@ -103,6 +118,15 @@ static inline int of_dma_router_register(struct device_node *np,

#define of_dma_router_free of_dma_controller_free

+static inline int
+devm_of_dma_router_register(struct device *dev, struct device_node *np,
+ void *(*of_dma_route_allocate)
+ (struct of_phandle_args *, struct of_dma *),
+ struct dma_router *dma_router)
+{
+ return -ENODEV;
+}
+
static inline struct dma_chan *of_dma_request_slave_channel(struct device_node *np,
const char *name)
{
--
2.43.0