Skip to contentSkip to conversation

net: ipa: pass the correct size when freeing DMA memory

PATCH Applied Alex Elder 3 participants 3 messages Dec 3, 2020 – Dec 4, 2020

Subsystems (3)
lore
Share & tools
lore

Alex Elder

author
#0 lore raw

PATCH 1/1 net: ipa: pass the correct size when freeing DMA memory

When the coherent memory is freed in gsi_trans_pool_exit_dma(), we are mistakenly passing the size of a single element in the pool rather than the actual allocated size. Fix this bug.

Fixes 9dd441e4ed575 ("soc: qcom: ipa: GSI transactions")
---
 drivers/net/ipa/gsi_trans.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/ipa/gsi_trans.c +6 -1
index e8599bb948c08..6c3ed5b17b80c 100644
@@ -156,6 +156,9 @@ int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool,
 	/* The allocator will give us a power-of-2 number of pages.  But we
 	 * can't guarantee that, so request it.  That way we won't waste any
 	 * memory that would be available beyond the required space.
+	 *
+	 * Note that gsi_trans_pool_exit_dma() assumes the total allocated
+	 * size is exactly (count * size).
 	 */
 	total_size = get_order(total_size) << PAGE_SHIFT;
 
@@ -175,7 +178,9 @@ int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool,
 
 void gsi_trans_pool_exit_dma(struct device *dev, struct gsi_trans_pool *pool)
 {
-	dma_free_coherent(dev, pool->size, pool->base, pool->addr);
+	size_t total_size = pool->count * pool->size;
+
+	dma_free_coherent(dev, total_size, pool->base, pool->addr);
 	memset(pool, 0, sizeof(*pool));
 }
 
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Alex Elder

When the coherent memory is freed in gsi_trans_pool_exit_dma(), we are mistakenly passing the size of a single element in the pool rather than the actual allocated size. Fix this bug.

Fixes 9dd441e4ed575 ("soc: qcom: ipa: GSI transactions")

Regards,
Bjorn

Quoted 32 lines
---
 drivers/net/ipa/gsi_trans.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/ipa/gsi_trans.c +6 -1
index e8599bb948c08..6c3ed5b17b80c 100644
@@ -156,6 +156,9 @@ int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool,
 	/* The allocator will give us a power-of-2 number of pages.  But we
 	 * can't guarantee that, so request it.  That way we won't waste any
 	 * memory that would be available beyond the required space.
+	 *
+	 * Note that gsi_trans_pool_exit_dma() assumes the total allocated
+	 * size is exactly (count * size).
 	 */
 	total_size = get_order(total_size) << PAGE_SHIFT;
 
@@ -175,7 +178,9 @@ int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool,
 
 void gsi_trans_pool_exit_dma(struct device *dev, struct gsi_trans_pool *pool)
 {
-	dma_free_coherent(dev, pool->size, pool->base, pool->addr);
+	size_t total_size = pool->count * pool->size;
+
+	dma_free_coherent(dev, total_size, pool->base, pool->addr);
 	memset(pool, 0, sizeof(*pool));
 }
 
Signature · 1 line
2.20.1
maintainer Applied
#2 lore raw
Quoted 10 lines · On Thu, 3 Dec 2020 17:28:16 -0600 Bjorn Andersson wrote:
Quoted 8 lines

When the coherent memory is freed in gsi_trans_pool_exit_dma(), we are mistakenly passing the size of a single element in the pool rather than the actual allocated size. Fix this bug.

Fixes 9dd441e4ed575 ("soc: qcom: ipa: GSI transactions")

Applied, thanks!