2022-02-22 05:52:42

by Dāvis Mosāns

[permalink] [raw]
Subject: [PATCH] dmaengine: fix locking for dma_channel_rebalance

dma_channel_rebalance comment says:
> Must be called under dma_list_mutex

We have few places where it wasn't done and could cause crashes.
So invoke it only when it's under mutex.
---
drivers/dma/dmaengine.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 2cfa8458b51be..5198bdf7ee804 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -1098,7 +1098,10 @@ 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);
@@ -1124,7 +1127,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.35.1