From 1028166948f7116f4dcddc74094125db0a7595c8 Mon Sep 17 00:00:00 2001
From: Romuald JEANNE <romuald.jeanne@st.com>
Date: Mon, 10 Dec 2018 15:34:56 +0100
Subject: [PATCH 32/52] ARM: stm32mp1-r0-rc3: DMA

---
 drivers/dma/stm32-dma.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c
index 4830f8e..1f9d606 100644
--- a/drivers/dma/stm32-dma.c
+++ b/drivers/dma/stm32-dma.c
@@ -212,6 +212,7 @@ struct stm32_dma_desc {
 	u32 num_sgs;
 	dma_addr_t dma_buf;
 	void *dma_buf_cpu;
+	u32 dma_buf_size;
 	struct stm32_dma_sg_req sg_req[];
 };
 
@@ -1224,6 +1225,7 @@ static int stm32_dma_mdma_prep_slave_sg(struct stm32_dma_chan *chan,
 					       &desc->dma_buf);
 	if (!desc->dma_buf_cpu)
 		return -ENOMEM;
+	desc->dma_buf_size = chan->sram_size;
 
 	sram_period = chan->sram_size / 2;
 
@@ -1316,7 +1318,7 @@ static int stm32_dma_mdma_prep_slave_sg(struct stm32_dma_chan *chan,
 	}
 free_alloc:
 	gen_pool_free(dmadev->sram_pool, (unsigned long)desc->dma_buf_cpu,
-		      chan->sram_size);
+		      desc->dma_buf_size);
 	return ret;
 }
 
@@ -1437,7 +1439,7 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_slave_sg(
 
 		gen_pool_free(dmadev->sram_pool,
 			      (unsigned long)desc->dma_buf_cpu,
-			      chan->sram_size);
+			      desc->dma_buf_size);
 	}
 	kfree(desc);
 
@@ -1462,6 +1464,7 @@ static int stm32_dma_mdma_prep_dma_cyclic(struct stm32_dma_chan *chan,
 					       &desc->dma_buf);
 	if (!desc->dma_buf_cpu)
 		return -ENOMEM;
+	desc->dma_buf_size = 2 * chan->sram_size;
 
 	memset(&config, 0, sizeof(config));
 	mem = buf_addr;
@@ -1511,7 +1514,7 @@ static int stm32_dma_mdma_prep_dma_cyclic(struct stm32_dma_chan *chan,
 err:
 	gen_pool_free(dmadev->sram_pool,
 		      (unsigned long)desc->dma_buf_cpu,
-		      chan->sram_size);
+		      desc->dma_buf_size);
 	return ret;
 }
 
@@ -1813,7 +1816,7 @@ static void stm32_dma_desc_free(struct virt_dma_desc *vdesc)
 
 		gen_pool_free(dmadev->sram_pool,
 			      (unsigned long)desc->dma_buf_cpu,
-			      chan->sram_size);
+			      desc->dma_buf_size);
 	}
 
 	kfree(desc);
-- 
2.7.4

