dmaengine.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] dmaengine: fix locking for dma_channel_rebalance
@ 2022-02-22  1:58 Dāvis Mosāns
  2022-02-22  2:18 ` Dāvis Mosāns
  0 siblings, 1 reply; 2+ messages in thread
From: Dāvis Mosāns @ 2022-02-22  1:58 UTC (permalink / raw)
  To: linux-kernel; +Cc: Vinod Koul, dmaengine, Dāvis Mosāns

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-22  2:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-22  1:58 [PATCH] dmaengine: fix locking for dma_channel_rebalance Dāvis Mosāns
2022-02-22  2:18 ` Dāvis Mosāns

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).