Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

+11 -1
+8 -1
include/sound/memalloc.h
··· 94 94 size_t offset) 95 95 { 96 96 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; 98 102 addr &= ~((dma_addr_t)PAGE_SIZE - 1); 99 103 return addr + offset % PAGE_SIZE; 100 104 } ··· 110 106 size_t offset) 111 107 { 112 108 struct snd_sg_buf *sgbuf = dmab->private_data; 109 + 110 + if (!sgbuf) 111 + return dmab->area + offset; 113 112 return sgbuf->table[offset >> PAGE_SHIFT].buf + offset % PAGE_SIZE; 114 113 } 115 114
+3
sound/core/sgbuf.c
··· 142 142 struct snd_sg_buf *sg = dmab->private_data; 143 143 unsigned int start, end, pg; 144 144 145 + if (!sg) 146 + return size; 147 + 145 148 start = ofs >> PAGE_SHIFT; 146 149 end = (ofs + size - 1) >> PAGE_SHIFT; 147 150 /* check page continuity */