The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] ALSA: memalloc: Fix DMA allocation retry cleanup
@ 2026-11-19 10:09 Sreeraj S Kurup
  2026-11-19 10:48 ` [PATCH v2] " Sreeraj S Kurup
  0 siblings, 1 reply; 3+ messages in thread
From: Sreeraj S Kurup @ 2026-11-19 10:09 UTC (permalink / raw)
  To: perex, tiwai; +Cc: linux-kernel, linux-sound, Sreeraj S Kurup

do_alloc_pages() retries allocation with lower DMA zones when the
allocated address exceeds the device's coherent DMA mask.

However, the previous allocation is not freed before retrying,
leaking the allocated pages.

Also, if no suitable DMA zone is available, the function can return
an allocation outside the device's DMA mask.

Free the allocated pages before retrying and return NULL when no
suitable allocation can be obtained.

Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
 sound/core/memalloc.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index 5986e9b84ac0..9458f9cbee53 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -298,13 +298,17 @@ static void *do_alloc_pages(struct device *dev, size_t size, dma_addr_t *addr,
 		return p;
 	if ((*addr + size - 1) & ~dev->coherent_dma_mask) {
 		if (IS_ENABLED(CONFIG_ZONE_DMA32) && !(gfp & GFP_DMA32)) {
+			free_pages_exact(p, size);
 			gfp |= GFP_DMA32;
 			goto again;
 		}
 		if (IS_ENABLED(CONFIG_ZONE_DMA) && !(gfp & GFP_DMA)) {
+			free_pages_exact(p, size);
 			gfp = (gfp & ~GFP_DMA32) | GFP_DMA;
 			goto again;
 		}
+		free_pages_exact(p, size);
+		return NULL;
 	}
 #ifdef CONFIG_X86
 	if (wc)
-- 
2.55.0


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

end of thread, other threads:[~2026-11-19 12:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 10:09 [PATCH] ALSA: memalloc: Fix DMA allocation retry cleanup Sreeraj S Kurup
2026-11-19 10:48 ` [PATCH v2] " Sreeraj S Kurup
2026-11-19 12:34   ` Takashi Iwai

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