[PATCH v6 4/9] dmaengine: move channel devices to the DMA channel bus

From: Peng Fan (OSS)

Date: Thu Nov 12 2026 - 02:51:12 EST


From: Peng Fan <peng.fan@xxxxxxx>

Register each dma_chan_dev on dmaengine_chan_bus_type before
device_register() and make it a bus device instead of a class device.
Setting the bus before registration lets bus_add_device() take the bus
subsystem reference, so the matching bus_remove_device() calls drop
references that were actually acquired. Attach dma_dev_groups to the bus
and set the device release callback directly.

Keep the existing /sys/class/dma interface by registering a class_compat
named "dma" and creating a link for each channel device. The channel
devices now live on the DMA bus, while /sys/class/dma/dmaNchanM remains
available to userspace.

The bus is named "dmaengine-chan" rather than "dma" to avoid colliding
with the SuperH DMA bus, which is also named "dma" and is registered later
from a postcore_initcall. As a result the device's uevent SUBSYSTEM and
"subsystem" link use "dmaengine-chan", while /sys/class/dma is unchanged.

Remove the post-registration dev->bus assignment from the Tegra GPC DMA
driver. Leaving it in place would overwrite the bus selected by the DMA
engine core and reintroduce the reference imbalance.

The DMA channel bus match callback never matches, so no driver can bind
to these channel devices.

Signed-off-by: Peng Fan <peng.fan@xxxxxxx>
---
drivers/dma/dmaengine.c | 23 +++++++++++++++--------
drivers/dma/tegra186-gpc-dma.c | 1 -
2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index e1022d297674..45e328d28689 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -239,11 +239,7 @@ static void chan_dev_release(struct device *dev)
kfree(chan_dev);
}

-static struct class dma_devclass = {
- .name = "dma",
- .dev_groups = dma_dev_groups,
- .dev_release = chan_dev_release,
-};
+static struct class_compat *dma_chan_class;

/* --- client and device registration --- */

@@ -1115,8 +1111,9 @@ static int __dma_async_device_channel_register(struct dma_device *device,
goto err_free_dev;
}

- dmaengine_chan_dev(chan)->class = &dma_devclass;
dmaengine_chan_dev(chan)->parent = device->dev;
+ dmaengine_chan_dev(chan)->bus = &dmaengine_chan_bus_type;
+ dmaengine_chan_dev(chan)->release = chan_dev_release;
chan->chan_dev->chan = chan;
chan->chan_dev->dev_id = device->dev_id;
spin_lock_init(&chan->lock);
@@ -1128,6 +1125,11 @@ static int __dma_async_device_channel_register(struct dma_device *device,
rc = device_register(dmaengine_chan_dev(chan));
if (rc)
goto err_out_ida;
+
+ rc = class_compat_create_link(dma_chan_class, dmaengine_chan_dev(chan));
+ if (rc)
+ dev_warn(device->dev, "Failed to create compatibility class link\n");
+
chan->client_count = 0;
device->chancnt++;

@@ -1172,6 +1174,7 @@ static void __dma_async_device_channel_unregister(struct dma_device *device,
chan->chan_dev->chan = NULL;
mutex_unlock(&dma_list_mutex);
ida_free(&device->chan_ida, chan->chan_id);
+ class_compat_remove_link(dma_chan_class, dmaengine_chan_dev(chan));
device_unregister(dmaengine_chan_dev(chan));
free_percpu(chan->local);
}
@@ -1306,6 +1309,7 @@ int dma_async_device_register(struct dma_device *device)
mutex_lock(&dma_list_mutex);
chan->chan_dev->chan = NULL;
mutex_unlock(&dma_list_mutex);
+ class_compat_remove_link(dma_chan_class, dmaengine_chan_dev(chan));
device_unregister(dmaengine_chan_dev(chan));
free_percpu(chan->local);
}
@@ -1652,6 +1656,7 @@ static int dma_chan_bus_match(struct device *dev,
const struct bus_type dmaengine_chan_bus_type = {
.name = "dmaengine-chan",
.match = dma_chan_bus_match,
+ .dev_groups = dma_dev_groups,
};

static int __init dma_bus_init(void)
@@ -1665,9 +1670,11 @@ static int __init dma_bus_init(void)
if (err)
goto err_destroy_unmap_pool;

- err = class_register(&dma_devclass);
- if (err)
+ dma_chan_class = class_compat_register("dma");
+ if (!dma_chan_class) {
+ err = -ENOMEM;
goto err_unregister_bus;
+ }

dmaengine_debugfs_init();
return 0;
diff --git a/drivers/dma/tegra186-gpc-dma.c b/drivers/dma/tegra186-gpc-dma.c
index ec12b7288b43..93b136f875d4 100644
--- a/drivers/dma/tegra186-gpc-dma.c
+++ b/drivers/dma/tegra186-gpc-dma.c
@@ -1540,7 +1540,6 @@ static int tegra_dma_probe(struct platform_device *pdev)
tdc = to_tegra_dma_chan(chan);

if (use_iommu_map) {
- chdev->bus = pdev->dev.bus;
dma_coerce_mask_and_coherent(chdev, DMA_BIT_MASK(cdata->addr_bits));

ret = of_dma_configure_id(chdev, pdev->dev.of_node,

--
2.34.1