* [PATCH v2] mmc: sdhci-of-bst: Fix memory leak in sdhci_bst_alloc_bounce_buffer()
@ 2026-03-02 13:47 Felix Gu
2026-03-09 15:06 ` Ulf Hansson
0 siblings, 1 reply; 2+ messages in thread
From: Felix Gu @ 2026-03-02 13:47 UTC (permalink / raw)
To: Adrian Hunter, Ge Gordon, BST Linux Kernel Upstream Group,
Ulf Hansson, Albert Yang, Arnd Bergmann
Cc: linux-arm-kernel, linux-mmc, linux-kernel, Felix Gu
In sdhci_bst_alloc_bounce_buffer(), if dma_alloc_coherent() fails, the
function immediately returns -ENOMEM without releasing the reserved
memory, which results in a memory leak.
Add the missing of_reserved_mem_device_release() call before returning
-ENOMEM to properly clean up the reserved memory.
Fixes: 695824f45629 ("mmc: sdhci: add Black Sesame Technologies BST C1200 controller driver")
Signed-off-by: Felix Gu <ustc.gu@gmail.com>
---
Changes in v2:
- Fix Adrian's comment.
- Link to v1: https://lore.kernel.org/r/20260301-bst-v1-1-ddbc22ec3ed9@gmail.com
---
drivers/mmc/host/sdhci-of-bst.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/mmc/host/sdhci-of-bst.c b/drivers/mmc/host/sdhci-of-bst.c
index c124990a64f4..f8d3df715e1a 100644
--- a/drivers/mmc/host/sdhci-of-bst.c
+++ b/drivers/mmc/host/sdhci-of-bst.c
@@ -425,8 +425,10 @@ static int sdhci_bst_alloc_bounce_buffer(struct sdhci_host *host)
host->bounce_buffer = dma_alloc_coherent(mmc_dev(mmc), bounce_size,
&host->bounce_addr, GFP_KERNEL);
- if (!host->bounce_buffer)
+ if (!host->bounce_buffer) {
+ of_reserved_mem_device_release(mmc_dev(mmc));
return -ENOMEM;
+ }
host->bounce_buffer_size = bounce_size;
---
base-commit: 3fa5e5702a82d259897bd7e209469bc06368bf31
change-id: 20260301-bst-76bb7c6d7931
Best regards,
--
Felix Gu <ustc.gu@gmail.com>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] mmc: sdhci-of-bst: Fix memory leak in sdhci_bst_alloc_bounce_buffer()
2026-03-02 13:47 [PATCH v2] mmc: sdhci-of-bst: Fix memory leak in sdhci_bst_alloc_bounce_buffer() Felix Gu
@ 2026-03-09 15:06 ` Ulf Hansson
0 siblings, 0 replies; 2+ messages in thread
From: Ulf Hansson @ 2026-03-09 15:06 UTC (permalink / raw)
To: Felix Gu
Cc: Adrian Hunter, Ge Gordon, BST Linux Kernel Upstream Group,
Albert Yang, Arnd Bergmann, linux-arm-kernel, linux-mmc,
linux-kernel
On Mon, 2 Mar 2026 at 14:47, Felix Gu <ustc.gu@gmail.com> wrote:
>
> In sdhci_bst_alloc_bounce_buffer(), if dma_alloc_coherent() fails, the
> function immediately returns -ENOMEM without releasing the reserved
> memory, which results in a memory leak.
>
> Add the missing of_reserved_mem_device_release() call before returning
> -ENOMEM to properly clean up the reserved memory.
>
> Fixes: 695824f45629 ("mmc: sdhci: add Black Sesame Technologies BST C1200 controller driver")
> Signed-off-by: Felix Gu <ustc.gu@gmail.com>
Applied for next, thanks!
Kind regards
Uffe
> ---
> Changes in v2:
> - Fix Adrian's comment.
> - Link to v1: https://lore.kernel.org/r/20260301-bst-v1-1-ddbc22ec3ed9@gmail.com
> ---
> drivers/mmc/host/sdhci-of-bst.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mmc/host/sdhci-of-bst.c b/drivers/mmc/host/sdhci-of-bst.c
> index c124990a64f4..f8d3df715e1a 100644
> --- a/drivers/mmc/host/sdhci-of-bst.c
> +++ b/drivers/mmc/host/sdhci-of-bst.c
> @@ -425,8 +425,10 @@ static int sdhci_bst_alloc_bounce_buffer(struct sdhci_host *host)
>
> host->bounce_buffer = dma_alloc_coherent(mmc_dev(mmc), bounce_size,
> &host->bounce_addr, GFP_KERNEL);
> - if (!host->bounce_buffer)
> + if (!host->bounce_buffer) {
> + of_reserved_mem_device_release(mmc_dev(mmc));
> return -ENOMEM;
> + }
>
> host->bounce_buffer_size = bounce_size;
>
>
> ---
> base-commit: 3fa5e5702a82d259897bd7e209469bc06368bf31
> change-id: 20260301-bst-76bb7c6d7931
>
> Best regards,
> --
> Felix Gu <ustc.gu@gmail.com>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-03-09 15:06 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-02 13:47 [PATCH v2] mmc: sdhci-of-bst: Fix memory leak in sdhci_bst_alloc_bounce_buffer() Felix Gu
2026-03-09 15:06 ` Ulf Hansson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox