Skip to content

Commit d4732c9

Browse files
author
Jyri Sarha
committed
Audio: IIR: 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 and unloading process. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 584c496 commit d4732c9

5 files changed

Lines changed: 23 additions & 37 deletions

File tree

src/audio/eq_iir/eq_iir.c

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <sof/common.h>
1818
#include <rtos/panic.h>
1919
#include <sof/ipc/msg.h>
20-
#include <rtos/alloc.h>
2120
#include <rtos/init.h>
2221
#include <sof/lib/uuid.h>
2322
#include <sof/list.h>
@@ -60,18 +59,17 @@ static int eq_iir_init(struct processing_module *mod)
6059
return -EINVAL;
6160
}
6261

63-
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
62+
cd = mod_zalloc(mod, sizeof(*cd));
6463
if (!cd)
6564
return -ENOMEM;
6665

6766
md->private = cd;
6867

6968
/* component model data handler */
70-
cd->model_handler = comp_data_blob_handler_new(dev);
69+
cd->model_handler = mod_data_blob_handler_new(mod);
7170
if (!cd->model_handler) {
72-
comp_err(dev, "comp_data_blob_handler_new() failed.");
73-
ret = -ENOMEM;
74-
goto err;
71+
comp_err(dev, "mod_data_blob_handler_new() failed.");
72+
return -ENOMEM;
7573
}
7674

7775
/* Allocate and make a copy of the coefficients blob and reset IIR. If
@@ -80,27 +78,18 @@ static int eq_iir_init(struct processing_module *mod)
8078
ret = comp_init_data_blob(cd->model_handler, bs, cfg->data);
8179
if (ret < 0) {
8280
comp_err(dev, "comp_init_data_blob() failed with error: %d", ret);
83-
comp_data_blob_handler_free(cd->model_handler);
84-
goto err;
81+
return ret;
8582
}
8683

8784
for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
8885
iir_reset_df1(&cd->iir[i]);
8986

9087
return 0;
91-
err:
92-
rfree(cd);
93-
return ret;
9488
}
9589

9690
static int eq_iir_free(struct processing_module *mod)
9791
{
98-
struct comp_data *cd = module_get_private_data(mod);
99-
100-
eq_iir_free_delaylines(cd);
101-
comp_data_blob_handler_free(cd->model_handler);
102-
103-
rfree(cd);
92+
eq_iir_free_delaylines(mod);
10493
return 0;
10594
}
10695

@@ -144,7 +133,7 @@ static int eq_iir_process(struct processing_module *mod,
144133
/* Check for changed configuration */
145134
if (comp_is_new_data_blob_available(cd->model_handler)) {
146135
cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL);
147-
ret = eq_iir_new_blob(mod, cd, audio_stream_get_frm_fmt(source),
136+
ret = eq_iir_new_blob(mod, audio_stream_get_frm_fmt(source),
148137
audio_stream_get_frm_fmt(sink),
149138
audio_stream_get_channels(source));
150139
if (ret)
@@ -216,7 +205,7 @@ static int eq_iir_prepare(struct processing_module *mod,
216205

217206
/* Initialize EQ */
218207
if (cd->config) {
219-
ret = eq_iir_new_blob(mod, cd, source_format, sink_format, channels);
208+
ret = eq_iir_new_blob(mod, source_format, sink_format, channels);
220209
if (ret)
221210
return ret;
222211
}
@@ -234,7 +223,7 @@ static int eq_iir_reset(struct processing_module *mod)
234223
struct comp_data *cd = module_get_private_data(mod);
235224
int i;
236225

237-
eq_iir_free_delaylines(cd);
226+
eq_iir_free_delaylines(mod);
238227

239228
cd->eq_iir_func = NULL;
240229
for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)

src/audio/eq_iir/eq_iir.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ void eq_iir_s24_default(struct processing_module *mod, struct input_stream_buffe
5656
void eq_iir_s32_default(struct processing_module *mod, struct input_stream_buffer *bsource,
5757
struct output_stream_buffer *bsink, uint32_t frames);
5858

59-
int eq_iir_new_blob(struct processing_module *mod, struct comp_data *cd,
60-
enum sof_ipc_frame source_format, enum sof_ipc_frame sink_format,
61-
int channels);
59+
int eq_iir_new_blob(struct processing_module *mod, enum sof_ipc_frame source_format,
60+
enum sof_ipc_frame sink_format, int channels);
6261

6362
void eq_iir_set_passthrough_func(struct comp_data *cd,
6463
enum sof_ipc_frame source_format,
@@ -71,5 +70,5 @@ void eq_iir_pass(struct processing_module *mod, struct input_stream_buffer *bsou
7170

7271
int eq_iir_setup(struct processing_module *mod, int nch);
7372

74-
void eq_iir_free_delaylines(struct comp_data *cd);
73+
void eq_iir_free_delaylines(struct processing_module *mod);
7574
#endif /* __SOF_AUDIO_EQ_IIR_EQ_IIR_H__ */

src/audio/eq_iir/eq_iir_generic.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,16 @@ static void eq_iir_init_delay(struct iir_state_df1 *iir,
285285
}
286286
}
287287

288-
void eq_iir_free_delaylines(struct comp_data *cd)
288+
void eq_iir_free_delaylines(struct processing_module *mod)
289289
{
290+
struct comp_data *cd = module_get_private_data(mod);
290291
struct iir_state_df1 *iir = cd->iir;
291292
int i = 0;
292293

293294
/* Free the common buffer for all EQs and point then
294295
* each IIR channel delay line to NULL.
295296
*/
296-
rfree(cd->iir_delay);
297+
mod_free(mod, cd->iir_delay);
297298
cd->iir_delay = NULL;
298299
cd->iir_delay_size = 0;
299300
for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
@@ -315,7 +316,7 @@ int eq_iir_setup(struct processing_module *mod, int nch)
315316
int delay_size;
316317

317318
/* Free existing IIR channels data if it was allocated */
318-
eq_iir_free_delaylines(cd);
319+
eq_iir_free_delaylines(mod);
319320

320321
/* Set coefficients for each channel EQ from coefficient blob */
321322
delay_size = eq_iir_init_coef(mod, nch);
@@ -329,8 +330,7 @@ int eq_iir_setup(struct processing_module *mod, int nch)
329330
return 0;
330331

331332
/* Allocate all IIR channels data in a big chunk and clear it */
332-
cd->iir_delay = rzalloc(SOF_MEM_FLAG_USER,
333-
delay_size);
333+
cd->iir_delay = mod_zalloc(mod, delay_size);
334334
if (!cd->iir_delay) {
335335
comp_err(mod->dev, "eq_iir_setup(), delay allocation fail");
336336
return -ENOMEM;

src/audio/eq_iir/eq_iir_ipc3.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <sof/common.h>
1818
#include <rtos/panic.h>
1919
#include <sof/ipc/msg.h>
20-
#include <rtos/alloc.h>
2120
#include <rtos/init.h>
2221
#include <sof/lib/uuid.h>
2322
#include <sof/list.h>
@@ -298,10 +297,10 @@ static int eq_iir_verify_params(struct comp_dev *dev,
298297
return 0;
299298
}
300299

301-
int eq_iir_new_blob(struct processing_module *mod, struct comp_data *cd,
302-
enum sof_ipc_frame source_format, enum sof_ipc_frame sink_format,
303-
int channels)
300+
int eq_iir_new_blob(struct processing_module *mod, enum sof_ipc_frame source_format,
301+
enum sof_ipc_frame sink_format, int channels)
304302
{
303+
struct comp_data *cd = module_get_private_data(mod);
305304
int ret;
306305

307306
ret = eq_iir_setup(mod, channels);

src/audio/eq_iir/eq_iir_ipc4.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <sof/common.h>
1818
#include <rtos/panic.h>
1919
#include <sof/ipc/msg.h>
20-
#include <rtos/alloc.h>
2120
#include <rtos/init.h>
2221
#include <sof/lib/uuid.h>
2322
#include <sof/list.h>
@@ -77,10 +76,10 @@ static eq_iir_func eq_iir_find_func(struct processing_module *mod)
7776
return NULL;
7877
}
7978

80-
int eq_iir_new_blob(struct processing_module *mod, struct comp_data *cd,
81-
enum sof_ipc_frame source_format, enum sof_ipc_frame sink_format,
82-
int channels)
79+
int eq_iir_new_blob(struct processing_module *mod, enum sof_ipc_frame source_format,
80+
enum sof_ipc_frame sink_format, int channels)
8381
{
82+
struct comp_data *cd = module_get_private_data(mod);
8483
int ret;
8584

8685
ret = eq_iir_setup(mod, channels);

0 commit comments

Comments
 (0)