Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mmc: wmt-sdmmc: release DMA descriptors after stopping the host
@ 2026-10-19 13:53 Guanxin Li
  2026-10-19 14:29 ` Alexey Charkov
  0 siblings, 1 reply; 2+ messages in thread
From: Guanxin Li @ 2026-10-19 13:53 UTC (permalink / raw)
  To: Alexey Charkov, Krzysztof Kozlowski, Ulf Hansson, Guanxin Li,
	linux-arm-kernel, linux-mmc, linux-kernel

wmt_mci_remove() currently frees the DMA descriptor buffer before calling
mmc_remove_host() and freeing the controller IRQs. The controller may still
be using the descriptors, and an interrupt handler may still access them
during this window.

Stop the MMC host and free both IRQs before releasing the DMA buffer to
prevent DMA or interrupt accesses to the freed memory during device removal.

Signed-off-by: Guanxin Li <bruceli20040604@gmail.com>
---
 drivers/mmc/host/wmt-sdmmc.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/wmt-sdmmc.c b/drivers/mmc/host/wmt-sdmmc.c
index 489daee4f4fc..c44befabc909 100644
--- a/drivers/mmc/host/wmt-sdmmc.c
+++ b/drivers/mmc/host/wmt-sdmmc.c
@@ -896,14 +896,14 @@ static void wmt_mci_remove(struct platform_device *pdev)
 	writeb(0xFF, priv->sdmmc_base + SDMMC_STS1);
 
 	/* release the dma buffers */
-	dma_free_coherent(&pdev->dev, priv->mmc->max_blk_count * 16,
-			  priv->dma_desc_buffer, priv->dma_desc_device_addr);
+
 
 	mmc_remove_host(mmc);
 
 	free_irq(priv->irq_regular, priv);
 	free_irq(priv->irq_dma, priv);
-
+	dma_free_coherent(&pdev->dev, priv->mmc->max_blk_count * 16,
+			  priv->dma_desc_buffer, priv->dma_desc_device_addr);
 	iounmap(priv->sdmmc_base);
 
 	clk_disable_unprepare(priv->clk_sdmmc);
-- 
2.43.0



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

* Re: [PATCH] mmc: wmt-sdmmc: release DMA descriptors after stopping the host
  2026-10-19 13:53 [PATCH] mmc: wmt-sdmmc: release DMA descriptors after stopping the host Guanxin Li
@ 2026-10-19 14:29 ` Alexey Charkov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexey Charkov @ 2026-10-19 14:29 UTC (permalink / raw)
  To: Guanxin Li
  Cc: Krzysztof Kozlowski, Ulf Hansson, linux-arm-kernel, linux-mmc,
	linux-kernel

On Mon, Oct 19, 2026 at 5:53 PM Guanxin Li <bruceli20040604@gmail.com> wrote:
>
> wmt_mci_remove() currently frees the DMA descriptor buffer before calling
> mmc_remove_host() and freeing the controller IRQs. The controller may still
> be using the descriptors, and an interrupt handler may still access them
> during this window.
>
> Stop the MMC host and free both IRQs before releasing the DMA buffer to
> prevent DMA or interrupt accesses to the freed memory during device removal.
>
> Signed-off-by: Guanxin Li <bruceli20040604@gmail.com>
> ---
>  drivers/mmc/host/wmt-sdmmc.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/mmc/host/wmt-sdmmc.c b/drivers/mmc/host/wmt-sdmmc.c
> index 489daee4f4fc..c44befabc909 100644
> --- a/drivers/mmc/host/wmt-sdmmc.c
> +++ b/drivers/mmc/host/wmt-sdmmc.c
> @@ -896,14 +896,14 @@ static void wmt_mci_remove(struct platform_device *pdev)
>         writeb(0xFF, priv->sdmmc_base + SDMMC_STS1);
>
>         /* release the dma buffers */
> -       dma_free_coherent(&pdev->dev, priv->mmc->max_blk_count * 16,
> -                         priv->dma_desc_buffer, priv->dma_desc_device_addr);
> +

If you are moving the function call, please move the comment too (or
better yet delete it altogether, as it doesn't add much information).
And no double blank lines please.

>         mmc_remove_host(mmc);
>
>         free_irq(priv->irq_regular, priv);
>         free_irq(priv->irq_dma, priv);
> -
> +       dma_free_coherent(&pdev->dev, priv->mmc->max_blk_count * 16,
> +                         priv->dma_desc_buffer, priv->dma_desc_device_addr);
>         iounmap(priv->sdmmc_base);
>
>         clk_disable_unprepare(priv->clk_sdmmc);

Other than the above,

Reviewed-by: Alexey Charkov <alchark@gmail.com>

Best regards,
Alexey


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

end of thread, other threads:[~2026-10-19 14:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-19 13:53 [PATCH] mmc: wmt-sdmmc: release DMA descriptors after stopping the host Guanxin Li
2026-10-19 14:29 ` Alexey Charkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox