Skip to contentSkip to conversation

mmc: sdhci-of-bst: Fix memory leak in sdhci_bst_alloc_bounce_buffer()

PATCH Superseded Felix Gu 2 participants 3 messages Mar 1 – Mar 2

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Felix Gu

author
#0 lore raw

PATCH 1/1 mmc: sdhci-of-bst: Fix memory leak in sdhci_bst_alloc_bounce_buffer()

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")
---
 drivers/mmc/host/sdhci-of-bst.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-of-bst.c +3 -1
index c124990a64f4..79c945f4858e 100644
@@ -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(host->mmc));
 		return -ENOMEM;
+	}
 
 	host->bounce_buffer_size = bounce_size;
 

---
base-commit: 3fa5e5702a82d259897bd7e209469bc06368bf31
change-id: 20260301-bst-76bb7c6d7931

Best regards,

Signature · 1 line
Felix Gu <[email protected]>
maintainer
#1 lore raw
Quoted 18 lines · 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")
---
 drivers/mmc/host/sdhci-of-bst.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mmc/host/sdhci-of-bst.c +0 -0
index c124990a64f4..79c945f4858e 100644

drivers/mmc/host/sdhci-of-bst.c static int sdhci_bst_alloc_bounce_buffer(struct sdhci_host *host) · line 429

Quoted 6 lines
drivers/mmc/host/sdhci-of-bst.c +2 -1
@@ -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(host->mmc));

Please use the same expression for the device as the rest of the function i.e. change "mmc_dev(host->mmc)" to "mmc_dev(mmc)"

Quoted 11 lines
drivers/mmc/host/sdhci-of-bst.c +1 -1
 		return -ENOMEM;
+	}
 
 	host->bounce_buffer_size = bounce_size;
 
 
---

base-commit: 3fa5e5702a82d259897bd7e209469bc06368bf31
change-id: 20260301-bst-76bb7c6d7931

Best regards,

author
#2 lore raw
Quoted 3 lines

Please use the same expression for the device as the rest of the function i.e. change "mmc_dev(host->mmc)" to "mmc_dev(mmc)"

Hi Adrian,
I will update it in V2.

Best regards,
Felix