Skip to content

Commit 6a72bbd

Browse files
author
Jyri Sarha
committed
Audio: ASRC: Memory, blob, and fast_get allocs to module API
Allocate all memory, blob handlers, and fast_get() buffers through module API mod_alloc() and friends and remove all redundant rfree(), comp_data_blob_handler_free(), and fast_put() calls from module unload functions and init error branches. When resources are allocated through module API functions they are automatically freed when the module is unloaded. This simplifies error handling process. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent e4350ea commit 6a72bbd

5 files changed

Lines changed: 57 additions & 62 deletions

File tree

src/audio/asrc/asrc.c

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <sof/audio/ipc-config.h>
1212
#include <rtos/panic.h>
1313
#include <sof/ipc/msg.h>
14-
#include <rtos/alloc.h>
1514
#include <rtos/init.h>
1615
#include <sof/lib/uuid.h>
1716
#include <sof/math/numbers.h>
@@ -217,7 +216,7 @@ static int asrc_init(struct processing_module *mod)
217216
return -EINVAL;
218217
}
219218

220-
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
219+
cd = mod_zalloc(mod, sizeof(*cd));
221220
if (!cd)
222221
return -ENOMEM;
223222

@@ -242,7 +241,7 @@ static int asrc_init(struct processing_module *mod)
242241
return 0;
243242
}
244243

245-
static int asrc_initialize_buffers(struct asrc_farrow *src_obj)
244+
static int asrc_initialize_buffers(struct processing_module *mod, struct asrc_farrow *src_obj)
246245
{
247246
int32_t *buf_32;
248247
int16_t *buf_16;
@@ -261,7 +260,7 @@ static int asrc_initialize_buffers(struct asrc_farrow *src_obj)
261260
buffer_size = src_obj->buffer_length * sizeof(int32_t);
262261

263262
for (ch = 0; ch < src_obj->num_channels; ch++) {
264-
buf_32 = rzalloc(SOF_MEM_FLAG_USER, buffer_size);
263+
buf_32 = mod_zalloc(mod, buffer_size);
265264

266265
if (!buf_32)
267266
return -ENOMEM;
@@ -272,7 +271,7 @@ static int asrc_initialize_buffers(struct asrc_farrow *src_obj)
272271
buffer_size = src_obj->buffer_length * sizeof(int16_t);
273272

274273
for (ch = 0; ch < src_obj->num_channels; ch++) {
275-
buf_16 = rzalloc(SOF_MEM_FLAG_USER, buffer_size);
274+
buf_16 = mod_zalloc(mod, buffer_size);
276275

277276
if (!buf_16)
278277
return -ENOMEM;
@@ -284,7 +283,7 @@ static int asrc_initialize_buffers(struct asrc_farrow *src_obj)
284283
return 0;
285284
}
286285

287-
static void asrc_release_buffers(struct asrc_farrow *src_obj)
286+
static void asrc_release_buffers(struct processing_module *mod, struct asrc_farrow *src_obj)
288287
{
289288
int32_t *buf_32;
290289
int16_t *buf_16;
@@ -299,7 +298,7 @@ static void asrc_release_buffers(struct asrc_farrow *src_obj)
299298

300299
if (buf_32) {
301300
src_obj->ring_buffers32[ch] = NULL;
302-
rfree(buf_32);
301+
mod_free(mod, buf_32);
303302
}
304303
}
305304
else
@@ -308,23 +307,17 @@ static void asrc_release_buffers(struct asrc_farrow *src_obj)
308307

309308
if (buf_16) {
310309
src_obj->ring_buffers16[ch] = NULL;
311-
rfree(buf_16);
310+
mod_free(mod, buf_16);
312311
}
313312
}
314313
}
315314

316315
static int asrc_free(struct processing_module *mod)
317316
{
318-
struct comp_data *cd = module_get_private_data(mod);
319317
struct comp_dev *dev = mod->dev;
320318

321319
comp_dbg(dev, "asrc_free()");
322320

323-
rfree(cd->buf);
324-
asrc_release_buffers(cd->asrc_obj);
325-
asrc_free_polyphase_filter(cd->asrc_obj);
326-
rfree(cd->asrc_obj);
327-
rfree(cd);
328321
return 0;
329322
}
330323

@@ -614,8 +607,7 @@ static int asrc_prepare(struct processing_module *mod,
614607
cd->buf_size = (cd->source_frames_max + cd->sink_frames_max) *
615608
frame_bytes;
616609

617-
cd->buf = rzalloc(SOF_MEM_FLAG_USER,
618-
cd->buf_size);
610+
cd->buf = mod_zalloc(mod, cd->buf_size);
619611
if (!cd->buf) {
620612
cd->buf_size = 0;
621613
comp_err(dev, "asrc_prepare(), allocation fail for size %d",
@@ -632,16 +624,15 @@ static int asrc_prepare(struct processing_module *mod,
632624

633625
/* Get required size and allocate memory for ASRC */
634626
sample_bits = sample_bytes * 8;
635-
ret = asrc_get_required_size(dev, &cd->asrc_size,
627+
ret = asrc_get_required_size(mod, &cd->asrc_size,
636628
audio_stream_get_channels(&sourceb->stream),
637629
sample_bits);
638630
if (ret) {
639631
comp_err(dev, "asrc_prepare(), get_required_size_bytes failed");
640632
goto err_free_buf;
641633
}
642634

643-
cd->asrc_obj = rzalloc(SOF_MEM_FLAG_USER,
644-
cd->asrc_size);
635+
cd->asrc_obj = mod_zalloc(mod, cd->asrc_size);
645636
if (!cd->asrc_obj) {
646637
comp_err(dev, "asrc_prepare(), allocation fail for size %d",
647638
cd->asrc_size);
@@ -659,7 +650,7 @@ static int asrc_prepare(struct processing_module *mod,
659650
fs_sec = cd->source_rate;
660651
}
661652

662-
ret = asrc_initialise(dev, cd->asrc_obj, audio_stream_get_channels(&sourceb->stream),
653+
ret = asrc_initialise(mod, cd->asrc_obj, audio_stream_get_channels(&sourceb->stream),
663654
fs_prim, fs_sec,
664655
ASRC_IOF_INTERLEAVED, ASRC_IOF_INTERLEAVED,
665656
ASRC_BM_LINEAR, cd->frames, sample_bits,
@@ -670,7 +661,7 @@ static int asrc_prepare(struct processing_module *mod,
670661
}
671662

672663
/* Allocate ring buffers */
673-
ret = asrc_initialize_buffers(cd->asrc_obj);
664+
ret = asrc_initialize_buffers(mod, cd->asrc_obj);
674665

675666
/* check for errors */
676667
if (ret) {
@@ -698,12 +689,12 @@ static int asrc_prepare(struct processing_module *mod,
698689
return 0;
699690

700691
err_free_asrc:
701-
asrc_release_buffers(cd->asrc_obj);
702-
rfree(cd->asrc_obj);
692+
asrc_release_buffers(mod, cd->asrc_obj);
693+
mod_free(mod, cd->asrc_obj);
703694
cd->asrc_obj = NULL;
704695

705696
err_free_buf:
706-
rfree(cd->buf);
697+
mod_free(mod, cd->buf);
707698
cd->buf = NULL;
708699

709700
err:
@@ -865,10 +856,10 @@ static int asrc_reset(struct processing_module *mod)
865856
asrc_dai_stop_timestamp(cd);
866857

867858
/* Free the allocations those were done in prepare() */
868-
asrc_release_buffers(cd->asrc_obj);
869-
asrc_free_polyphase_filter(cd->asrc_obj);
870-
rfree(cd->asrc_obj);
871-
rfree(cd->buf);
859+
asrc_release_buffers(mod, cd->asrc_obj);
860+
asrc_free_polyphase_filter(mod, cd->asrc_obj);
861+
mod_free(mod, cd->asrc_obj);
862+
mod_free(mod, cd->buf);
872863
cd->asrc_obj = NULL;
873864
cd->buf = NULL;
874865

0 commit comments

Comments
 (0)