Skip to content

Commit 3294951

Browse files
Jyri Sarhalgirdwood
authored andcommitted
audio: ring_buffer: use sof_ctx_alloc/free wrappers
Replace open-coded vregion vs heap allocation and free patterns in ring_buffer_free() and ring_buffer_create() with the new sof_ctx_alloc() and sof_ctx_free() wrappers. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent d3c41a6 commit 3294951

1 file changed

Lines changed: 7 additions & 24 deletions

File tree

src/audio/buffers/ring_buffer.c

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <sof/trace/trace.h>
88
#include <sof/lib/uuid.h>
99
#include <sof/lib/vregion.h>
10+
#include <sof/ctx_alloc.h>
1011

1112
#include <sof/audio/module_adapter/module/generic.h>
1213
#include <sof/audio/ring_buffer.h>
@@ -99,13 +100,8 @@ static void ring_buffer_free(struct sof_audio_buffer *audio_buffer)
99100
struct ring_buffer, audio_buffer);
100101
struct mod_alloc_ctx *alloc = audio_buffer->alloc;
101102

102-
if (alloc->vreg) {
103-
vregion_free(alloc->vreg, (__sparse_force void *)ring_buffer->_data_buffer);
104-
vregion_free(alloc->vreg, ring_buffer);
105-
} else {
106-
sof_heap_free(alloc->heap, (__sparse_force void *)ring_buffer->_data_buffer);
107-
sof_heap_free(alloc->heap, ring_buffer);
108-
}
103+
sof_ctx_free(alloc, (__sparse_force void *)ring_buffer->_data_buffer);
104+
sof_ctx_free(alloc, ring_buffer);
109105
}
110106

111107
static void ring_buffer_reset(struct sof_audio_buffer *audio_buffer)
@@ -296,17 +292,11 @@ struct ring_buffer *ring_buffer_create(struct comp_dev *dev, size_t min_availabl
296292
struct ring_buffer *ring_buffer;
297293
struct mod_alloc_ctx *alloc = dev->mod->priv.resources.alloc;
298294
struct k_heap *heap = alloc->heap;
299-
struct vregion *vreg = alloc->vreg;
300295
int memory_flags = (is_shared ? SOF_MEM_FLAG_COHERENT : 0) |
301296
user_get_buffer_memory_region(dev->drv);
302297

303298
/* allocate ring_buffer structure */
304-
if (!vreg)
305-
ring_buffer = sof_heap_alloc(heap, memory_flags, sizeof(*ring_buffer), 0);
306-
else if (is_shared)
307-
ring_buffer = vregion_alloc_coherent(vreg, VREGION_MEM_TYPE_INTERIM, sizeof(*ring_buffer));
308-
else
309-
ring_buffer = vregion_alloc(vreg, VREGION_MEM_TYPE_INTERIM, sizeof(*ring_buffer));
299+
ring_buffer = sof_ctx_alloc(alloc, memory_flags, sizeof(*ring_buffer), 0);
310300
if (!ring_buffer)
311301
return NULL;
312302

@@ -382,12 +372,8 @@ struct ring_buffer *ring_buffer_create(struct comp_dev *dev, size_t min_availabl
382372

383373
void *data_buf;
384374

385-
if (vreg)
386-
data_buf = vregion_alloc_align(vreg, VREGION_MEM_TYPE_INTERIM, ring_buffer->data_buffer_size,
387-
PLATFORM_DCACHE_ALIGN);
388-
else
389-
data_buf = sof_heap_alloc(heap, user_get_buffer_memory_region(dev->drv),
390-
ring_buffer->data_buffer_size, PLATFORM_DCACHE_ALIGN);
375+
data_buf = sof_ctx_alloc(alloc, user_get_buffer_memory_region(dev->drv),
376+
ring_buffer->data_buffer_size, PLATFORM_DCACHE_ALIGN);
391377

392378
if (!data_buf)
393379
goto err;
@@ -402,9 +388,6 @@ struct ring_buffer *ring_buffer_create(struct comp_dev *dev, size_t min_availabl
402388
return ring_buffer;
403389
err:
404390
tr_err(&ring_buffer_tr, "Ring buffer creation failure");
405-
if (vreg)
406-
vregion_free(vreg, ring_buffer);
407-
else
408-
sof_heap_free(heap, ring_buffer);
391+
sof_ctx_free(alloc, ring_buffer);
409392
return NULL;
410393
}

0 commit comments

Comments
 (0)