Skip to contentSkip to conversation

ALSA: memalloc: Store snd_dma_buffer.addr for continuous pages, too

PATCH Superseded Takashi Iwai 1 participant 2 messages Aug 4, 2021 Sound

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA: memalloc: Store snd_dma_buffer.addr for continuous pages, too

In the recent fix commit eda80d7c9c4d ("ALSA: memalloc: Fix regression with SNDRV_DMA_TYPE_CONTINUOUS"), we replaced the pfn argument of the remap_page_pfn() call from the uninitialized dmab->addr. It was the right fix, but it'd be more generic if we actually initialize dmab->area for SNDRV_DMA_TYPE_CONTINOUS, too. e.g. the field is used in the common snd_sgbuf_get_addr(), too.

This patch adds the initialization of addr field and does revert of the previous change to refer to it again in the mmap call.

---
 sound/core/memalloc.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
sound/core/memalloc.c +5 -2
index 084b2600a423..21f57f1e81a4 100644
@@ -242,8 +242,11 @@ EXPORT_SYMBOL(snd_sgbuf_get_chunk_size);
 static void *snd_dma_continuous_alloc(struct snd_dma_buffer *dmab, size_t size)
 {
 	gfp_t gfp = snd_mem_get_gfp_flags(dmab, GFP_KERNEL);
+	void *p = alloc_pages_exact(size, gfp);
 
-	return alloc_pages_exact(size, gfp);
+	if (p)
+		dmab->addr = page_to_phys(virt_to_page(dmab->area));
+	return p;
 }
 
 static void snd_dma_continuous_free(struct snd_dma_buffer *dmab)
@@ -255,7 +258,7 @@ static int snd_dma_continuous_mmap(struct snd_dma_buffer *dmab,
 				   struct vm_area_struct *area)
 {
 	return remap_pfn_range(area, area->vm_start,
-			       page_to_pfn(virt_to_page(dmab->area)),
+			       dmab->addr >> PAGE_SHIFT,
 			       area->vm_end - area->vm_start,
 			       area->vm_page_prot);
 }
Signature · 1 line
2.26.2
#1 lore raw
Quoted 8 lines · Takashi Iwai

In the recent fix commit eda80d7c9c4d ("ALSA: memalloc: Fix regression with SNDRV_DMA_TYPE_CONTINUOUS"), we replaced the pfn argument of the remap_page_pfn() call from the uninitialized dmab->addr. It was the right fix, but it'd be more generic if we actually initialize dmab->area for SNDRV_DMA_TYPE_CONTINOUS, too. e.g. the field is used in the common snd_sgbuf_get_addr(), too.

Quoted 4 lines

This patch adds the initialization of addr field and does revert of the previous change to refer to it again in the mmap call.

Scratch this one, an old patch was submitted wrongly. Will resubmit the right one.

Takashi