[PATCH 3/5] mmc: sdhci: fix align_buffer memory leak on re-initialization
Peng Fan (OSS)
peng.fan at oss.nxp.com
Sun Jul 12 15:07:30 CEST 2026
From: Peng Fan <peng.fan at nxp.com>
sdhci_init() allocates a 512KB aligned bounce buffer for controllers
with SDHCI_QUIRK_32BIT_DMA_ADDR. In the non-DM code path, sdhci_init()
is registered as ops->init and called on every mmc_init(). Each call
allocates a new buffer without checking or freeing the previous one,
leaking 512KB per re-initialization.
Fix by guarding the allocation with !host->align_buffer so it only
allocates on the first call.
Signed-off-by: Peng Fan <peng.fan at nxp.com>
---
drivers/mmc/sdhci.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/mmc/sdhci.c b/drivers/mmc/sdhci.c
index 08594e10266..ef20e881542 100644
--- a/drivers/mmc/sdhci.c
+++ b/drivers/mmc/sdhci.c
@@ -733,7 +733,8 @@ static int sdhci_init(struct mmc *mmc)
*/
host->force_align_buffer = true;
#else
- if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) {
+ if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) &&
+ !host->align_buffer) {
host->align_buffer = memalign(8, 512 * 1024);
if (!host->align_buffer) {
log_err("Aligned buffer alloc failed\n");
--
2.51.0
More information about the U-Boot
mailing list