Skip to content

Commit 331531a

Browse files
author
Jyri Sarha
committed
Audio: crossover: All memory allocations through module API
Allocate all memory through module API mod_alloc() and friends and remove all redundant rfree() calls from module unload functions and init error branches. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 27a0659 commit 331531a

File tree

3 files changed

+34
-39
lines changed

3 files changed

+34
-39
lines changed

src/audio/crossover/crossover.c

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <sof/common.h>
1616
#include <rtos/panic.h>
1717
#include <sof/ipc/msg.h>
18-
#include <rtos/alloc.h>
1918
#include <rtos/init.h>
2019
#include <sof/lib/uuid.h>
2120
#include <sof/math/iir_df1.h>
@@ -47,12 +46,13 @@ DECLARE_TR_CTX(crossover_tr, SOF_UUID(crossover_uuid), LOG_LEVEL_INFO);
4746
* \brief Reset the state (coefficients and delay) of the crossover filter
4847
* across all channels
4948
*/
50-
static void crossover_reset_state(struct comp_data *cd)
49+
static void crossover_reset_state(struct processing_module *mod,
50+
struct comp_data *cd)
5151
{
5252
int i;
5353

5454
for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
55-
crossover_reset_state_ch(&cd->state[i]);
55+
crossover_reset_state_ch(mod, &cd->state[i]);
5656
}
5757

5858
/**
@@ -156,7 +156,8 @@ static int crossover_assign_sinks(struct processing_module *mod,
156156
* high/low pass filter.
157157
* \param[out] lr4 initialized struct
158158
*/
159-
static int crossover_init_coef_lr4(struct sof_eq_iir_biquad *coef,
159+
static int crossover_init_coef_lr4(struct processing_module *mod,
160+
struct sof_eq_iir_biquad *coef,
160161
struct iir_state_df1 *lr4)
161162
{
162163
int ret;
@@ -169,8 +170,7 @@ static int crossover_init_coef_lr4(struct sof_eq_iir_biquad *coef,
169170
* in series due to identity. To maintain the structure of
170171
* iir_state_df1, it requires two copies of coefficients in a row.
171172
*/
172-
lr4->coef = rzalloc(SOF_MEM_FLAG_USER,
173-
sizeof(struct sof_eq_iir_biquad) * 2);
173+
lr4->coef = mod_zalloc(mod, sizeof(struct sof_eq_iir_biquad) * 2);
174174
if (!lr4->coef)
175175
return -ENOMEM;
176176

@@ -189,8 +189,7 @@ static int crossover_init_coef_lr4(struct sof_eq_iir_biquad *coef,
189189
* delay[0..1] -> state for first biquad
190190
* delay[2..3] -> state for second biquad
191191
*/
192-
lr4->delay = rzalloc(SOF_MEM_FLAG_USER,
193-
sizeof(uint64_t) * CROSSOVER_NUM_DELAYS_LR4);
192+
lr4->delay = mod_zalloc(mod, sizeof(uint64_t) * CROSSOVER_NUM_DELAYS_LR4);
194193
if (!lr4->delay)
195194
return -ENOMEM;
196195

@@ -203,7 +202,8 @@ static int crossover_init_coef_lr4(struct sof_eq_iir_biquad *coef,
203202
/**
204203
* \brief Initializes the crossover coefficients for one channel
205204
*/
206-
int crossover_init_coef_ch(struct sof_eq_iir_biquad *coef,
205+
int crossover_init_coef_ch(struct processing_module *mod,
206+
struct sof_eq_iir_biquad *coef,
207207
struct crossover_state *ch_state,
208208
int32_t num_sinks)
209209
{
@@ -214,12 +214,12 @@ int crossover_init_coef_ch(struct sof_eq_iir_biquad *coef,
214214

215215
for (i = 0; i < num_lr4s; i++) {
216216
/* Get the low pass coefficients */
217-
err = crossover_init_coef_lr4(&coef[j],
217+
err = crossover_init_coef_lr4(mod, &coef[j],
218218
&ch_state->lowpass[i]);
219219
if (err < 0)
220220
return -EINVAL;
221221
/* Get the high pass coefficients */
222-
err = crossover_init_coef_lr4(&coef[j + 1],
222+
err = crossover_init_coef_lr4(mod, &coef[j + 1],
223223
&ch_state->highpass[i]);
224224
if (err < 0)
225225
return -EINVAL;
@@ -259,13 +259,13 @@ static int crossover_init_coef(struct processing_module *mod, int nch)
259259
/* Collect the coef array and assign it to every channel */
260260
crossover = config->coef;
261261
for (ch = 0; ch < nch; ch++) {
262-
err = crossover_init_coef_ch(crossover, &cd->state[ch],
262+
err = crossover_init_coef_ch(mod, crossover, &cd->state[ch],
263263
config->num_sinks);
264264
/* Free all previously allocated blocks in case of an error */
265265
if (err < 0) {
266266
comp_err(mod->dev, "crossover_init_coef(), could not assign coefficients to ch %d",
267267
ch);
268-
crossover_reset_state(cd);
268+
crossover_reset_state(mod, cd);
269269
return err;
270270
}
271271
}
@@ -282,7 +282,7 @@ static int crossover_setup(struct processing_module *mod, int nch)
282282
int ret = 0;
283283

284284
/* Reset any previous state */
285-
crossover_reset_state(cd);
285+
crossover_reset_state(mod, cd);
286286

287287
/* Assign LR4 coefficients from config */
288288
ret = crossover_init_coef(mod, nch);
@@ -312,40 +312,34 @@ static int crossover_init(struct processing_module *mod)
312312
return -ENOMEM;
313313
}
314314

315-
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
315+
cd = mod_zalloc(mod, sizeof(*cd));
316316
if (!cd)
317317
return -ENOMEM;
318318

319319
md->private = cd;
320320

321321
/* Handler for configuration data */
322-
cd->model_handler = comp_data_blob_handler_new(dev);
322+
cd->model_handler = mod_data_blob_handler_new(mod);
323323
if (!cd->model_handler) {
324324
comp_err(dev, "comp_data_blob_handler_new() failed.");
325-
ret = -ENOMEM;
326-
goto cd_fail;
325+
return -ENOMEM;
327326
}
328327

329328
/* Get configuration data and reset Crossover state */
330329
ret = comp_init_data_blob(cd->model_handler, bs, ipc_crossover->data);
331330
if (ret < 0) {
332331
comp_err(dev, "comp_init_data_blob() failed.");
333-
goto cd_fail;
332+
return ret;
334333
}
335334

336335
ret = crossover_output_pin_init(mod);
337336
if (ret < 0) {
338337
comp_err(dev, "crossover_init_output_pins() failed.");
339-
goto cd_fail;
338+
return ret;
340339
}
341340

342-
crossover_reset_state(cd);
341+
crossover_reset_state(mod, cd);
343342
return 0;
344-
345-
cd_fail:
346-
comp_data_blob_handler_free(cd->model_handler);
347-
rfree(cd);
348-
return ret;
349343
}
350344

351345
/**
@@ -357,11 +351,8 @@ static int crossover_free(struct processing_module *mod)
357351

358352
comp_info(mod->dev, "crossover_free()");
359353

360-
comp_data_blob_handler_free(cd->model_handler);
361-
362-
crossover_reset_state(cd);
354+
crossover_reset_state(mod, cd);
363355

364-
rfree(cd);
365356
return 0;
366357
}
367358

@@ -616,7 +607,7 @@ static int crossover_reset(struct processing_module *mod)
616607

617608
comp_info(mod->dev, "crossover_reset()");
618609

619-
crossover_reset_state(cd);
610+
crossover_reset_state(mod, cd);
620611

621612
cd->crossover_process = NULL;
622613
cd->crossover_split = NULL;

src/audio/multiband_drc/multiband_drc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static int multiband_drc_init_coef(struct processing_module *mod, int16_t nch, u
142142
/* Crossover: collect the coef array and assign it to every channel */
143143
crossover = config->crossover_coef;
144144
for (ch = 0; ch < nch; ch++) {
145-
ret = crossover_init_coef_ch(crossover, &state->crossover[ch],
145+
ret = crossover_init_coef_ch(mod, crossover, &state->crossover[ch],
146146
config->num_bands);
147147
/* Free all previously allocated blocks in case of an error */
148148
if (ret < 0) {

src/include/module/crossover/crossover_common.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef __SOF_CROSSOVER_COMMON_H__
99
#define __SOF_CROSSOVER_COMMON_H__
1010

11+
#include <sof/audio/module_adapter/module/generic.h>
1112
#include <sof/math/iir_df1.h>
1213
#include <user/eq.h>
1314

@@ -39,17 +40,19 @@ typedef void (*crossover_split)(int32_t in, int32_t out[],
3940
extern const crossover_split crossover_split_fnmap[];
4041

4142
/* crossover init function */
42-
int crossover_init_coef_ch(struct sof_eq_iir_biquad *coef,
43+
int crossover_init_coef_ch(struct processing_module *mod,
44+
struct sof_eq_iir_biquad *coef,
4345
struct crossover_state *ch_state,
4446
int32_t num_sinks);
4547

4648
/**
4749
* \brief Reset the state of an LR4 filter.
4850
*/
49-
static inline void crossover_reset_state_lr4(struct iir_state_df1 *lr4)
51+
static inline void crossover_reset_state_lr4(struct processing_module *mod,
52+
struct iir_state_df1 *lr4)
5053
{
51-
rfree(lr4->coef);
52-
rfree(lr4->delay);
54+
mod_free(mod, lr4->coef);
55+
mod_free(mod, lr4->delay);
5356

5457
lr4->coef = NULL;
5558
lr4->delay = NULL;
@@ -59,13 +62,14 @@ static inline void crossover_reset_state_lr4(struct iir_state_df1 *lr4)
5962
* \brief Reset the state (coefficients and delay) of the crossover filter
6063
* of a single channel.
6164
*/
62-
static inline void crossover_reset_state_ch(struct crossover_state *ch_state)
65+
static inline void crossover_reset_state_ch(struct processing_module *mod,
66+
struct crossover_state *ch_state)
6367
{
6468
int i;
6569

6670
for (i = 0; i < CROSSOVER_MAX_LR4; i++) {
67-
crossover_reset_state_lr4(&ch_state->lowpass[i]);
68-
crossover_reset_state_lr4(&ch_state->highpass[i]);
71+
crossover_reset_state_lr4(mod, &ch_state->lowpass[i]);
72+
crossover_reset_state_lr4(mod, &ch_state->highpass[i]);
6973
}
7074
}
7175

0 commit comments

Comments
 (0)