diff options
author | Takashi Iwai <tiwai@suse.de> | 2020-06-15 18:00:44 +0200 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2020-06-15 18:01:52 +0200 |
commit | 2a1f3368bff609504cdc984cdb7cef467bb0b2b0 (patch) | |
tree | 91b48322462746d447147f7448a886e22fbbf768 /include/sound/memalloc.h | |
parent | 28e60dbb83f76b18acade913dfdb029cd908c9b0 (diff) | |
download | linux-2a1f3368bff609504cdc984cdb7cef467bb0b2b0.tar.bz2 |
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/20200615160045.2703-4-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'include/sound/memalloc.h')
-rw-r--r-- | include/sound/memalloc.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/include/sound/memalloc.h b/include/sound/memalloc.h index 3b47832b1c1f..5daa937684a4 100644 --- a/include/sound/memalloc.h +++ b/include/sound/memalloc.h @@ -94,7 +94,11 @@ static inline dma_addr_t snd_sgbuf_get_addr(struct snd_dma_buffer *dmab, size_t offset) { struct snd_sg_buf *sgbuf = dmab->private_data; - dma_addr_t addr = sgbuf->table[offset >> PAGE_SHIFT].addr; + dma_addr_t addr; + + if (!sgbuf) + return dmab->addr + offset; + addr = sgbuf->table[offset >> PAGE_SHIFT].addr; addr &= ~((dma_addr_t)PAGE_SIZE - 1); return addr + offset % PAGE_SIZE; } @@ -106,6 +110,9 @@ static inline void *snd_sgbuf_get_ptr(struct snd_dma_buffer *dmab, size_t offset) { struct snd_sg_buf *sgbuf = dmab->private_data; + + if (!sgbuf) + return dmab->area + offset; return sgbuf->table[offset >> PAGE_SHIFT].buf + offset % PAGE_SIZE; } |