linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 1/1] net: ipa: pass the correct size when freeing DMA memory
@ 2020-12-03 21:51 Alex Elder
  2020-12-03 23:28 ` Bjorn Andersson
  0 siblings, 1 reply; 3+ messages in thread
From: Alex Elder @ 2020-12-03 21:51 UTC (permalink / raw)
  To: davem, kuba
  Cc: swboyd, sujitka, evgreen, cpratapa, bjorn.andersson, subashab,
	netdev, linux-kernel

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")
Reported-by: Stephen Boyd <swboyd@chromium.org>
Tested-by: Sujit Kautkar <sujitka@chromium.org>
Signed-off-by: Alex Elder <elder@linaro.org>
---
 drivers/net/ipa/gsi_trans.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c
index e8599bb948c08..6c3ed5b17b80c 100644
--- a/drivers/net/ipa/gsi_trans.c
+++ b/drivers/net/ipa/gsi_trans.c
@@ -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));
 }
 
-- 
2.20.1


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

* Re: [PATCH net 1/1] net: ipa: pass the correct size when freeing DMA memory
  2020-12-03 21:51 [PATCH net 1/1] net: ipa: pass the correct size when freeing DMA memory Alex Elder
@ 2020-12-03 23:28 ` Bjorn Andersson
  2020-12-04 22:41   ` Jakub Kicinski
  0 siblings, 1 reply; 3+ messages in thread
From: Bjorn Andersson @ 2020-12-03 23:28 UTC (permalink / raw)
  To: Alex Elder
  Cc: davem, kuba, swboyd, sujitka, evgreen, cpratapa, subashab,
	netdev, linux-kernel

On Thu 03 Dec 15:51 CST 2020, Alex Elder wrote:

> 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")
> Reported-by: Stephen Boyd <swboyd@chromium.org>
> Tested-by: Sujit Kautkar <sujitka@chromium.org>
> Signed-off-by: Alex Elder <elder@linaro.org>

Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Regards,
Bjorn

> ---
>  drivers/net/ipa/gsi_trans.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c
> index e8599bb948c08..6c3ed5b17b80c 100644
> --- a/drivers/net/ipa/gsi_trans.c
> +++ b/drivers/net/ipa/gsi_trans.c
> @@ -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));
>  }
>  
> -- 
> 2.20.1
> 

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

* Re: [PATCH net 1/1] net: ipa: pass the correct size when freeing DMA memory
  2020-12-03 23:28 ` Bjorn Andersson
@ 2020-12-04 22:41   ` Jakub Kicinski
  0 siblings, 0 replies; 3+ messages in thread
From: Jakub Kicinski @ 2020-12-04 22:41 UTC (permalink / raw)
  To: Bjorn Andersson
  Cc: Alex Elder, davem, swboyd, sujitka, evgreen, cpratapa, subashab,
	netdev, linux-kernel

On Thu, 3 Dec 2020 17:28:16 -0600 Bjorn Andersson wrote:
> > 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")
> > Reported-by: Stephen Boyd <swboyd@chromium.org>
> > Tested-by: Sujit Kautkar <sujitka@chromium.org>
> > Signed-off-by: Alex Elder <elder@linaro.org>  
> 
> Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>

Applied, thanks!

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

end of thread, other threads:[~2020-12-04 22:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03 21:51 [PATCH net 1/1] net: ipa: pass the correct size when freeing DMA memory Alex Elder
2020-12-03 23:28 ` Bjorn Andersson
2020-12-04 22:41   ` Jakub Kicinski

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).