Skip to content

Commit bd46ed1

Browse files
author
Jyri Sarha
committed
Audio: multiband_drc: 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. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 29769ae commit bd46ed1

File tree

2 files changed

+27
-41
lines changed

2 files changed

+27
-41
lines changed

src/audio/multiband_drc/multiband_drc.c

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,30 @@ SOF_DEFINE_REG_UUID(multiband_drc);
4242
DECLARE_TR_CTX(multiband_drc_tr, SOF_UUID(multiband_drc_uuid), LOG_LEVEL_INFO);
4343

4444
/* Called from multiband_drc_setup() from multiband_drc_process(), so cannot be __cold */
45-
static void multiband_drc_reset_state(struct multiband_drc_state *state)
45+
static void multiband_drc_reset_state(struct processing_module *mod,
46+
struct multiband_drc_state *state)
4647
{
4748
int i;
4849

4950
/* Reset emphasis eq-iir state */
5051
for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
51-
multiband_drc_iir_reset_state_ch(&state->emphasis[i]);
52+
multiband_drc_iir_reset_state_ch(mod, &state->emphasis[i]);
5253

5354
/* Reset crossover state */
5455
for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
55-
crossover_reset_state_ch(&state->crossover[i]);
56+
crossover_reset_state_ch(mod, &state->crossover[i]);
5657

5758
/* Reset drc kernel state */
5859
for (i = 0; i < SOF_MULTIBAND_DRC_MAX_BANDS; i++)
5960
drc_reset_state(&state->drc[i]);
6061

6162
/* Reset deemphasis eq-iir state */
6263
for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
63-
multiband_drc_iir_reset_state_ch(&state->deemphasis[i]);
64+
multiband_drc_iir_reset_state_ch(mod, &state->deemphasis[i]);
6465
}
6566

66-
static int multiband_drc_eq_init_coef_ch(struct sof_eq_iir_biquad *coef,
67+
static int multiband_drc_eq_init_coef_ch(struct processing_module *mod,
68+
struct sof_eq_iir_biquad *coef,
6769
struct iir_state_df1 *eq)
6870
{
6971
int ret;
@@ -72,8 +74,7 @@ static int multiband_drc_eq_init_coef_ch(struct sof_eq_iir_biquad *coef,
7274
if (SOF_EMP_DEEMP_BIQUADS != SOF_IIR_DF1_4TH_NUM_BIQUADS)
7375
return -EINVAL;
7476

75-
eq->coef = rzalloc(SOF_MEM_FLAG_USER,
76-
sizeof(struct sof_eq_iir_biquad) * SOF_EMP_DEEMP_BIQUADS);
77+
eq->coef = mod_zalloc(mod, sizeof(struct sof_eq_iir_biquad) * SOF_EMP_DEEMP_BIQUADS);
7778
if (!eq->coef)
7879
return -ENOMEM;
7980

@@ -86,8 +87,7 @@ static int multiband_drc_eq_init_coef_ch(struct sof_eq_iir_biquad *coef,
8687
* delay[0..1] -> state for first biquad
8788
* delay[2..3] -> state for second biquad
8889
*/
89-
eq->delay = rzalloc(SOF_MEM_FLAG_USER,
90-
sizeof(uint64_t) * CROSSOVER_NUM_DELAYS_LR4);
90+
eq->delay = mod_zalloc(mod, sizeof(uint64_t) * CROSSOVER_NUM_DELAYS_LR4);
9191
if (!eq->delay)
9292
return -ENOMEM;
9393

@@ -148,7 +148,7 @@ static int multiband_drc_init_coef(struct processing_module *mod, int16_t nch, u
148148
if (ret < 0) {
149149
comp_err(dev,
150150
"multiband_drc_init_coef(), could not assign coeffs to ch %d", ch);
151-
goto err;
151+
return ret;
152152
}
153153
}
154154

@@ -157,12 +157,12 @@ static int multiband_drc_init_coef(struct processing_module *mod, int16_t nch, u
157157
/* Emphasis: collect the coef array and assign it to every channel */
158158
emphasis = config->emp_coef;
159159
for (ch = 0; ch < nch; ch++) {
160-
ret = multiband_drc_eq_init_coef_ch(emphasis, &state->emphasis[ch]);
160+
ret = multiband_drc_eq_init_coef_ch(mod, emphasis, &state->emphasis[ch]);
161161
/* Free all previously allocated blocks in case of an error */
162162
if (ret < 0) {
163163
comp_err(dev, "multiband_drc_init_coef(), could not assign coeffs to ch %d",
164164
ch);
165-
goto err;
165+
return ret;
166166
}
167167
}
168168

@@ -171,12 +171,12 @@ static int multiband_drc_init_coef(struct processing_module *mod, int16_t nch, u
171171
/* Deemphasis: collect the coef array and assign it to every channel */
172172
deemphasis = config->deemp_coef;
173173
for (ch = 0; ch < nch; ch++) {
174-
ret = multiband_drc_eq_init_coef_ch(deemphasis, &state->deemphasis[ch]);
174+
ret = multiband_drc_eq_init_coef_ch(mod, deemphasis, &state->deemphasis[ch]);
175175
/* Free all previously allocated blocks in case of an error */
176176
if (ret < 0) {
177177
comp_err(dev, "multiband_drc_init_coef(), could not assign coeffs to ch %d",
178178
ch);
179-
goto err;
179+
return ret;
180180
}
181181
}
182182

@@ -188,22 +188,18 @@ static int multiband_drc_init_coef(struct processing_module *mod, int16_t nch, u
188188
if (ret < 0) {
189189
comp_err(dev,
190190
"multiband_drc_init_coef(), could not init pre delay buffers");
191-
goto err;
191+
return ret;
192192
}
193193

194194
ret = drc_set_pre_delay_time(&state->drc[i],
195195
cd->config->drc_coef[i].pre_delay_time, rate);
196196
if (ret < 0) {
197197
comp_err(dev, "multiband_drc_init_coef(), could not set pre delay time");
198-
goto err;
198+
return ret;
199199
}
200200
}
201201

202202
return 0;
203-
204-
err:
205-
multiband_drc_reset_state(state);
206-
return ret;
207203
}
208204

209205
/* Called from multiband_drc_process(), so cannot be __cold */
@@ -213,7 +209,7 @@ static int multiband_drc_setup(struct processing_module *mod, int16_t channels,
213209
struct multiband_drc_comp_data *cd = module_get_private_data(mod);
214210

215211
/* Reset any previous state */
216-
multiband_drc_reset_state(&cd->state);
212+
multiband_drc_reset_state(mod, &cd->state);
217213

218214
/* Setup Crossover, Emphasis EQ, Deemphasis EQ, and DRC */
219215
return multiband_drc_init_coef(mod, channels, rate);
@@ -243,7 +239,7 @@ static int multiband_drc_init(struct processing_module *mod)
243239
return -EINVAL;
244240
}
245241

246-
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
242+
cd = mod_zalloc(mod, sizeof(*cd));
247243
if (!cd)
248244
return -ENOMEM;
249245

@@ -258,40 +254,29 @@ static int multiband_drc_init(struct processing_module *mod)
258254
multiband_drc_process_enable(&cd->process_enabled);
259255

260256
/* Handler for configuration data */
261-
cd->model_handler = comp_data_blob_handler_new(dev);
257+
cd->model_handler = mod_data_blob_handler_new(mod);
262258
if (!cd->model_handler) {
263259
comp_err(dev, "comp_data_blob_handler_new() failed.");
264-
ret = -ENOMEM;
265-
goto cd_fail;
260+
return -ENOMEM;
266261
}
267262

268263
/* Get configuration data and reset DRC state */
269264
ret = comp_init_data_blob(cd->model_handler, bs, cfg->data);
270265
if (ret < 0) {
271266
comp_err(dev, "comp_init_data_blob() failed.");
272-
goto cd_fail;
267+
return ret;
273268
}
274-
multiband_drc_reset_state(&cd->state);
269+
multiband_drc_reset_state(mod, &cd->state);
275270

276271
return 0;
277-
278-
cd_fail:
279-
comp_data_blob_handler_free(cd->model_handler);
280-
rfree(cd);
281-
return ret;
282272
}
283273

284274
__cold static int multiband_drc_free(struct processing_module *mod)
285275
{
286-
struct multiband_drc_comp_data *cd = module_get_private_data(mod);
287-
288276
assert_can_be_cold();
289277

290278
comp_info(mod->dev, "multiband_drc_free()");
291279

292-
comp_data_blob_handler_free(cd->model_handler);
293-
294-
rfree(cd);
295280
return 0;
296281
}
297282

@@ -415,7 +400,7 @@ static int multiband_drc_reset(struct processing_module *mod)
415400

416401
comp_info(mod->dev, "multiband_drc_reset()");
417402

418-
multiband_drc_reset_state(&cd->state);
403+
multiband_drc_reset_state(mod, &cd->state);
419404

420405
cd->source_format = 0;
421406
cd->multiband_drc_func = NULL;

src/audio/multiband_drc/multiband_drc.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ static inline multiband_drc_func multiband_drc_find_proc_func_pass(enum sof_ipc_
8989
return NULL;
9090
}
9191

92-
static inline void multiband_drc_iir_reset_state_ch(struct iir_state_df1 *iir)
92+
static inline void multiband_drc_iir_reset_state_ch(struct processing_module *mod,
93+
struct iir_state_df1 *iir)
9394
{
94-
rfree(iir->coef);
95-
rfree(iir->delay);
95+
mod_free(mod, iir->coef);
96+
mod_free(mod, iir->delay);
9697

9798
iir->coef = NULL;
9899
iir->delay = NULL;

0 commit comments

Comments
 (0)