[PATCH v2 4/4] dmaengine: rebalance a dynamically registered channel under dma_list_mutex
From: Daniel Byrne
Date: Mon Nov 30 2026 - 14:58:32 EST
dma_async_device_channel_register() and
dma_async_device_channel_unregister() call dma_channel_rebalance()
without dma_list_mutex, which the function requires. It clears every
slot of the channel table and repopulates it from a walk of the device
list, so a concurrent locked rebalance from dmaengine_get() or a device
registration interleaves with it. Public channels lose their table
entries until the next one, and a device release can delete the entry
the unlocked walk is on. The device's channel count is bumped without
the mutex on the same path and dropped under it on the other.
Take the mutex around the two rebalances and the count. Neither caller
holds it, and the helpers underneath take and drop it themselves.
Fixes: e81274cd6b52 ("dmaengine: add support to dynamic register/unregister of channels")
Signed-off-by: Daniel Byrne <daniel1.byrne@xxxxxxxxx>
---
New in v2.
drivers/dma/dmaengine.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 85a98aae6a97..49ecbdaf6dbb 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -1137,7 +1137,9 @@ static int __dma_async_device_channel_register(struct dma_device *device,
goto err_free_local;
}
chan->client_count = 0;
+ mutex_lock(&dma_list_mutex);
device->chancnt++;
+ mutex_unlock(&dma_list_mutex);
return 0;
@@ -1159,7 +1161,9 @@ int dma_async_device_channel_register(struct dma_device *device,
if (rc < 0)
return rc;
+ mutex_lock(&dma_list_mutex);
dma_channel_rebalance();
+ mutex_unlock(&dma_list_mutex);
return 0;
}
EXPORT_SYMBOL_GPL(dma_async_device_channel_register);
@@ -1227,7 +1231,9 @@ void dma_async_device_channel_unregister(struct dma_device *device,
struct dma_chan *chan)
{
__dma_async_device_channel_unregister(device, chan);
+ mutex_lock(&dma_list_mutex);
dma_channel_rebalance();
+ mutex_unlock(&dma_list_mutex);
}
EXPORT_SYMBOL_GPL(dma_async_device_channel_unregister);
--
2.43.0