Skip to content

Commit 2a1f336

Browse files
committed
ALSA: memalloc: Make SG-buffer helper usable for continuous buffer, too
We have a few helper functions for making the access to the buffer address easier on SG-buffer. Those are specific to the buffer that is allocated with SG-buffer type, and it makes hard to use both SG and non-SG buffers in the same code. This patch adds a few simple checks and lets the helpers to deal with both SG- and continuous buffers gracefully. It's a preliminary step for the upcoming patch that mimics the buffer type on the fly. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Iwai <[email protected]>
1 parent 28e60db commit 2a1f336

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

include/sound/memalloc.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,11 @@ static inline dma_addr_t snd_sgbuf_get_addr(struct snd_dma_buffer *dmab,
9494
size_t offset)
9595
{
9696
struct snd_sg_buf *sgbuf = dmab->private_data;
97-
dma_addr_t addr = sgbuf->table[offset >> PAGE_SHIFT].addr;
97+
dma_addr_t addr;
98+
99+
if (!sgbuf)
100+
return dmab->addr + offset;
101+
addr = sgbuf->table[offset >> PAGE_SHIFT].addr;
98102
addr &= ~((dma_addr_t)PAGE_SIZE - 1);
99103
return addr + offset % PAGE_SIZE;
100104
}
@@ -106,6 +110,9 @@ static inline void *snd_sgbuf_get_ptr(struct snd_dma_buffer *dmab,
106110
size_t offset)
107111
{
108112
struct snd_sg_buf *sgbuf = dmab->private_data;
113+
114+
if (!sgbuf)
115+
return dmab->area + offset;
109116
return sgbuf->table[offset >> PAGE_SHIFT].buf + offset % PAGE_SIZE;
110117
}
111118

sound/core/sgbuf.c

+3
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ unsigned int snd_sgbuf_get_chunk_size(struct snd_dma_buffer *dmab,
142142
struct snd_sg_buf *sg = dmab->private_data;
143143
unsigned int start, end, pg;
144144

145+
if (!sg)
146+
return size;
147+
145148
start = ofs >> PAGE_SHIFT;
146149
end = (ofs + size - 1) >> PAGE_SHIFT;
147150
/* check page continuity */

0 commit comments

Comments
 (0)