Skip to content

Commit 6afe1dd

Browse files
lyakhkv2019i
authored andcommitted
buffer: don't access stream internals in buffer_new()
Don't access struct audio_stream internals in buffer_new(), pass buffer flags to buffer_alloc() instead. Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
1 parent d8ce56c commit 6afe1dd

9 files changed

Lines changed: 12 additions & 14 deletions

File tree

src/audio/buffer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ DECLARE_SOF_RT_UUID("buffer", buffer_uuid, 0x42544c92, 0x8e92, 0x4e41,
2727
0xb6, 0x79, 0x34, 0x51, 0x9f, 0x1c, 0x1d, 0x28);
2828
DECLARE_TR_CTX(buffer_tr, SOF_UUID(buffer_uuid), LOG_LEVEL_INFO);
2929

30-
struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t align)
30+
struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t flags, uint32_t align)
3131
{
3232
struct comp_buffer *buffer;
3333
struct comp_buffer __sparse_cache *buffer_c;
@@ -59,6 +59,9 @@ struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t align)
5959
return NULL;
6060
}
6161

62+
buffer->stream.underrun_permitted = !!(flags & SOF_BUF_UNDERRUN_PERMITTED);
63+
buffer->stream.overrun_permitted = !!(flags & SOF_BUF_OVERRUN_PERMITTED);
64+
6265
list_init(&buffer->source_list);
6366
list_init(&buffer->sink_list);
6467

src/audio/chain_dma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ static int chain_task_init(struct comp_dev *dev, uint8_t host_dma_id, uint8_t li
589589

590590
fifo_size = ALIGN_UP_INTERNAL(fifo_size, addr_align);
591591

592-
cd->dma_buffer = buffer_alloc(fifo_size, SOF_MEM_CAPS_DMA, addr_align);
592+
cd->dma_buffer = buffer_alloc(fifo_size, SOF_MEM_CAPS_DMA, 0, addr_align);
593593

594594
if (!cd->dma_buffer) {
595595
comp_err(dev, "chain_task_init(): failed to alloc dma buffer");

src/audio/dai-legacy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ static int dai_params(struct comp_dev *dev,
573573
return err;
574574
}
575575
} else {
576-
dd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA,
576+
dd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA, 0,
577577
addr_align);
578578
if (!dd->dma_buffer) {
579579
comp_err(dev, "dai_params(): failed to alloc dma buffer");

src/audio/dai-zephyr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ static int dai_params(struct comp_dev *dev, struct sof_ipc_stream_params *params
827827
return err;
828828
}
829829
} else {
830-
dd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA,
830+
dd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA, 0,
831831
addr_align);
832832
if (!dd->dma_buffer) {
833833
comp_err(dev, "dai_params(): failed to alloc dma buffer");

src/audio/host-legacy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ int host_zephyr_params(struct host_data *hd, struct comp_dev *dev,
787787
goto out;
788788
}
789789
} else {
790-
hd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA,
790+
hd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA, 0,
791791
addr_align);
792792
if (!hd->dma_buffer) {
793793
comp_err(dev, "host_params(): failed to alloc dma buffer");

src/audio/host-zephyr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ int host_zephyr_params(struct host_data *hd, struct comp_dev *dev,
847847
goto out;
848848
}
849849
} else {
850-
hd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA,
850+
hd->dma_buffer = buffer_alloc(buffer_size, SOF_MEM_CAPS_DMA, 0,
851851
addr_align);
852852
if (!hd->dma_buffer) {
853853
comp_err(dev, "host_params(): failed to alloc dma buffer");

src/audio/module_adapter/module_adapter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ int module_adapter_prepare(struct comp_dev *dev)
348348
if (list_is_empty(&mod->sink_buffer_list)) {
349349
for (i = 0; i < mod->num_output_buffers; i++) {
350350
struct comp_buffer *buffer = buffer_alloc(buff_size, SOF_MEM_CAPS_RAM,
351-
PLATFORM_DCACHE_ALIGN);
351+
0, PLATFORM_DCACHE_ALIGN);
352352
if (!buffer) {
353353
comp_err(dev, "module_adapter_prepare(): failed to allocate local buffer");
354354
ret = -ENOMEM;

src/include/sof/audio/buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ struct buffer_cb_free {
189189
} while (0)
190190

191191
/* pipeline buffer creation and destruction */
192-
struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t align);
192+
struct comp_buffer *buffer_alloc(uint32_t size, uint32_t caps, uint32_t flags, uint32_t align);
193193
struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc);
194194
int buffer_set_size(struct comp_buffer __sparse_cache *buffer, uint32_t size);
195195
void buffer_free(struct comp_buffer *buffer);

src/ipc/ipc-helper.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,12 @@ struct comp_buffer *buffer_new(const struct sof_ipc_buffer *desc)
4444
desc->size, desc->comp.pipeline_id, desc->comp.id, desc->flags);
4545

4646
/* allocate buffer */
47-
buffer = buffer_alloc(desc->size, desc->caps, PLATFORM_DCACHE_ALIGN);
47+
buffer = buffer_alloc(desc->size, desc->caps, desc->flags, PLATFORM_DCACHE_ALIGN);
4848
if (buffer) {
4949
buffer->id = desc->comp.id;
5050
buffer->pipeline_id = desc->comp.pipeline_id;
5151
buffer->core = desc->comp.core;
5252

53-
buffer->stream.underrun_permitted = desc->flags &
54-
SOF_BUF_UNDERRUN_PERMITTED;
55-
buffer->stream.overrun_permitted = desc->flags &
56-
SOF_BUF_OVERRUN_PERMITTED;
57-
5853
memcpy_s(&buffer->tctx, sizeof(struct tr_ctx),
5954
&buffer_tr, sizeof(struct tr_ctx));
6055
}

0 commit comments

Comments
 (0)