summaryrefslogtreecommitdiff
path: root/kernel/dma
diff options
context:
space:
mode:
authorMarek Szyprowski <m.szyprowski@samsung.com>2026-10-26 10:54:12 +0100
committerMarek Szyprowski <m.szyprowski@samsung.com>2026-11-05 08:55:38 +0100
commit494f40ffabcdc8d9fa4012b2c972690f25a0a40f (patch)
tree08eac0bf3d58dcd46ec34c25325392d0b3fb704b /kernel/dma
parent6628e7d4c6b25c8d18f1345e3a20d21829aae7e4 (diff)
dma-coherent: serialize reserved memory pool initialization
Multiple devices can share the same "shared-dma-pool" reserved memory region, in which case the dma_coherent_mem structure is created by the first device attached to it and stored in rmem->priv. To avoid the potential race, serialize the check and initialization of rmem->priv with a mutex. Fixes: 7bfa5ab6fa1b ("drivers: dma-coherent: add initialization from device tree") Cc: stable@vger.kernel.org Link: https://lore.kernel.org/r/20261026095423.966856-2-m.szyprowski@samsung.com Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Diffstat (limited to 'kernel/dma')
-rw-r--r--kernel/dma/coherent.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/kernel/dma/coherent.c b/kernel/dma/coherent.c
index 4d0266893bcc..ac62b6bd3d0d 100644
--- a/kernel/dma/coherent.c
+++ b/kernel/dma/coherent.c
@@ -7,6 +7,7 @@
#include <linux/slab.h>
#include <linux/kernel.h>
#include <linux/module.h>
+#include <linux/mutex.h>
#include <linux/dma-direct.h>
#include <linux/dma-map-ops.h>
@@ -335,10 +336,18 @@ static phys_addr_t dma_reserved_default_memory_base __initdata;
static phys_addr_t dma_reserved_default_memory_size __initdata;
#endif
+static DEFINE_MUTEX(rmem_dma_mutex);
+
static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev)
{
- struct dma_coherent_mem *mem = rmem->priv;
+ struct dma_coherent_mem *mem;
+ /*
+ * Multiple devices can share the same pool and may be probed
+ * concurrently, so serialize the initialization of rmem->priv.
+ */
+ guard(mutex)(&rmem_dma_mutex);
+ mem = rmem->priv;
if (!mem) {
mem = dma_init_coherent_memory(rmem->base, rmem->base,
rmem->size, true);