Skip to content

Commit 7fb3a9c

Browse files
author
Jyri Sarha
committed
Audio: SRC: All memory allocations through module
Change all memory allocations to go through module API mod_alloc(), mod_zalloc(), and mod_free(). The mod_free() calls are dropped form error handling branches and from src_free() as the memory is anyway freed as the module should unload shortly. Signed-off-by: Jyri Sarha <jyri.sarha@linux.intel.com>
1 parent 07c0036 commit 7fb3a9c

File tree

6 files changed

+14
-20
lines changed

6 files changed

+14
-20
lines changed

src/audio/src/src.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static int src_prepare(struct processing_module *mod,
6060
if (ret < 0)
6161
return ret;
6262

63-
ret = src_allocate_copy_stages(mod->dev, a,
63+
ret = src_allocate_copy_stages(mod, a,
6464
src_table1[a->idx_out][a->idx_in],
6565
src_table2[a->idx_out][a->idx_in]);
6666
if (ret < 0)

src/audio/src/src_common.c

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,9 @@ int src_params_general(struct processing_module *mod,
531531
}
532532

533533
/* free any existing delay lines. TODO reuse if same size */
534-
rfree(cd->delay_lines);
534+
mod_free(mod, cd->delay_lines);
535535

536-
cd->delay_lines = rballoc(SOF_MEM_FLAG_USER, delay_lines_size);
536+
cd->delay_lines = mod_alloc(mod, delay_lines_size);
537537
if (!cd->delay_lines) {
538538
comp_err(dev, "src_params(): failed to alloc cd->delay_lines, delay_lines_size = %zu",
539539
delay_lines_size);
@@ -594,7 +594,7 @@ int src_param_set(struct comp_dev *dev, struct comp_data *cd)
594594
return 0;
595595
}
596596

597-
int src_allocate_copy_stages(struct comp_dev *dev, struct src_param *prm,
597+
int src_allocate_copy_stages(struct processing_module *mod, struct src_param *prm,
598598
const struct src_stage *stage_src1,
599599
const struct src_stage *stage_src2)
600600
{
@@ -607,10 +607,9 @@ int src_allocate_copy_stages(struct comp_dev *dev, struct src_param *prm,
607607
size_t tap_size = sizeof(int32_t);
608608
#endif
609609

610-
stage_dst = rmalloc(SOF_MEM_FLAG_USER,
611-
2 * sizeof(*stage_dst));
610+
stage_dst = mod_alloc(mod, 2 * sizeof(*stage_dst));
612611
if (!stage_dst) {
613-
comp_err(dev, "failed to allocate stages");
612+
comp_err(mod->dev, "failed to allocate stages");
614613
return -ENOMEM;
615614
}
616615

@@ -622,20 +621,18 @@ int src_allocate_copy_stages(struct comp_dev *dev, struct src_param *prm,
622621
coef_size[1] = tap_size * stage_src2->filter_length;
623622

624623
if (coef_size[0] == 0 || coef_size[1] == 0) {
625-
comp_err(dev,
624+
comp_err(mod->dev,
626625
"illegal zero coefficient vector size for unsupported conversion request %d to %d",
627626
prm->in_fs[prm->idx_in], prm->out_fs[prm->idx_out]);
628-
rfree(stage_dst);
629627
return -EINVAL;
630628
}
631629

632630
stage_dst[0].coefs = fast_get(stage_src1->coefs, coef_size[0]);
633631
stage_dst[1].coefs = fast_get(stage_src2->coefs, coef_size[1]);
634632

635633
if (!stage_dst[0].coefs || !stage_dst[1].coefs) {
636-
comp_err(dev, "failed to allocate coefficients");
634+
comp_err(mod->dev, "failed to allocate coefficients");
637635
fast_put(stage_dst[0].coefs);
638-
rfree(stage_dst);
639636
return -ENOMEM;
640637
}
641638

@@ -707,21 +704,19 @@ int src_reset(struct processing_module *mod)
707704

708705
__cold int src_free(struct processing_module *mod)
709706
{
707+
#if CONFIG_FAST_GET
710708
struct comp_data *cd = module_get_private_data(mod);
709+
#endif
711710

712711
assert_can_be_cold();
713712

714713
comp_info(mod->dev, "src_free()");
715714

716-
/* Free dynamically reserved buffers for SRC algorithm */
717-
rfree(cd->delay_lines);
718715
#if CONFIG_FAST_GET
719716
if (cd->param.stage1) {
720717
fast_put(cd->param.stage1->coefs);
721718
fast_put(cd->param.stage2->coefs);
722719
}
723-
rfree((void *)cd->param.stage1);
724720
#endif
725-
rfree(cd);
726721
return 0;
727722
}

src/audio/src/src_common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static inline int src_fallback(struct comp_data *cd,
215215
return 0;
216216
}
217217

218-
int src_allocate_copy_stages(struct comp_dev *dev, struct src_param *prm,
218+
int src_allocate_copy_stages(struct processing_module *mod, struct src_param *prm,
219219
const struct src_stage *stage_src1,
220220
const struct src_stage *stage_src2);
221221
int src_rate_check(const void *spec);

src/audio/src/src_ipc3.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ int src_init(struct processing_module *mod)
178178
return -EINVAL;
179179
}
180180

181-
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
181+
cd = mod_zalloc(mod, sizeof(*cd));
182182
if (!cd)
183183
return -ENOMEM;
184184

src/audio/src/src_ipc4.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ __cold int src_init(struct processing_module *mod)
209209
return -EINVAL;
210210
}
211211

212-
cd = rzalloc(SOF_MEM_FLAG_USER, sizeof(*cd));
212+
cd = mod_zalloc(mod, sizeof(*cd));
213213
if (!cd)
214214
return -ENOMEM;
215215

@@ -240,7 +240,6 @@ __cold int src_init(struct processing_module *mod)
240240
default:
241241
comp_err(dev, "src_init(): Illegal sample depth %d",
242242
cd->ipc_config.base.audio_fmt.depth);
243-
rfree(cd);
244243
return -EINVAL;
245244
}
246245

src/audio/src/src_lite.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static int src_lite_prepare(struct processing_module *mod,
4343
if (ret < 0)
4444
return ret;
4545

46-
ret = src_allocate_copy_stages(mod->dev, a,
46+
ret = src_allocate_copy_stages(mod, a,
4747
src_table1[a->idx_out][a->idx_in],
4848
src_table2[a->idx_out][a->idx_in]);
4949
if (ret < 0)

0 commit comments

Comments
 (0)