]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
mmc: sdhci: fix align_buffer memory leak on re-initialization
authorPeng Fan <peng.fan@nxp.com>
Mon, 13 Jul 2026 13:32:54 +0000 (21:32 +0800)
committerPeng Fan <peng.fan@nxp.com>
Wed, 29 Jul 2026 03:15:55 +0000 (11:15 +0800)
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.

Reviewed-by: Tanmay Kathpalia <tanmay.kathpalia@altera.com>
Signed-off-by: Tanmay Kathpalia <tanmay.kathpalia@altera.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
drivers/mmc/sdhci.c

index 71a6d8ea2f567067e11f3d76716362da8fe90bcb..962a99cd05a0b6cb990b8b3efb90269b1c0a97f0 100644 (file)
@@ -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");