From: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
To: sreekuttan2156239@gmail.com, perex@perex.cz, tiwai@suse.de
Cc: linux-kernel@vger.kernel.org, linux-sound@vger.kernel.org
Subject: [PATCH v2] ALSA: memalloc: Fix DMA allocation retry cleanup
Date: Thu, 19 Nov 2026 10:48:59 +0000 [thread overview]
Message-ID: <20261119104859.2807-1-sreekuttan2156239@gmail.com> (raw)
In-Reply-To: <20261119100928.2740-1-sreekuttan2156239@gmail.com>
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.
Avoid retrying GFP_DMA32 after GFP_DMA has been selected, and skip
the DMA mask check when the coherent DMA mask is unset.
Free the allocated pages before retrying and return NULL when no
suitable allocation can be obtained.
Fixes: dd164fbfdc20 ("ALSA: memalloc: Drop special handling of GFP for CONTINUOUS allocation")
Signed-off-by: Sreeraj S Kurup <sreekuttan2156239@gmail.com>
---
v2:
- Avoid retrying with GFP_DMA32 after GFP_DMA has been selected.
- Skip DMA mask validation when coherent_dma_mask is unset.
- Add Fixes trailer.
sound/core/memalloc.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/sound/core/memalloc.c b/sound/core/memalloc.c
index 5986e9b84ac0..8fec4a8fd219 100644
--- a/sound/core/memalloc.c
+++ b/sound/core/memalloc.c
@@ -294,17 +294,21 @@ static void *do_alloc_pages(struct device *dev, size_t size, dma_addr_t *addr,
if (!p)
return NULL;
*addr = page_to_phys(virt_to_page(p));
- if (!dev)
+ if (!dev || !dev->coherent_dma_mask)
return p;
if ((*addr + size - 1) & ~dev->coherent_dma_mask) {
- if (IS_ENABLED(CONFIG_ZONE_DMA32) && !(gfp & GFP_DMA32)) {
+ if (IS_ENABLED(CONFIG_ZONE_DMA32) && !(gfp & (GFP_DMA32 | GFP_DMA))) {
+ 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
next prev parent reply other threads:[~2026-11-19 10:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 10:09 [PATCH] " Sreeraj S Kurup
2026-11-19 10:48 ` Sreeraj S Kurup [this message]
2026-11-19 12:34 ` [PATCH v2] " Takashi Iwai
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119104859.2807-1-sreekuttan2156239@gmail.com \
--to=sreekuttan2156239@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®