Skip to content

Commit

Permalink
Audio: Improvement of multiband_drc memory allocation error handling.
Browse files Browse the repository at this point in the history
This check-in improves error handling in the multiband_drc
component by enabling error logging and returning -ENOMEM
if memory allocation fails. It replaces asserts with conditional
checks to detect and log errors during memory copy operations.
Finally, it streamlines the return logic in multiband_drc_setup
and propagates the init_coef error code.

Signed-off-by: Shriram Shastry <[email protected]>
  • Loading branch information
ShriramShastry committed May 30, 2024
1 parent 90c54a6 commit 73fb894
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/audio/multiband_drc/multiband_drc.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,25 @@ static void multiband_drc_reset_state(struct multiband_drc_state *state)
multiband_drc_iir_reset_state_ch(&state->deemphasis[i]);
}

static int multiband_drc_eq_init_coef_ch(struct sof_eq_iir_biquad *coef,
static int multiband_drc_eq_init_coef_ch(struct comp_dev *dev, struct sof_eq_iir_biquad *coef,
struct iir_state_df2t *eq)
{
int ret;

eq->coef = rzalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
sizeof(struct sof_eq_iir_biquad) * SOF_EMP_DEEMP_BIQUADS);
if (!eq->coef)
if (!eq->coef) {
comp_err(dev, "Failed to allocate EQ coefficients");
return -ENOMEM;
}

/* Coefficients of the first biquad and second biquad */
ret = memcpy_s(eq->coef, sizeof(struct sof_eq_iir_biquad) * SOF_EMP_DEEMP_BIQUADS,
coef, sizeof(struct sof_eq_iir_biquad) * SOF_EMP_DEEMP_BIQUADS);
assert(!ret);
if (ret) {
comp_err(dev, "Memory copy failed");
return ret;
}

/* EQ filters are two 2nd order filters, so only need 4 delay slots
* delay[0..1] -> state for first biquad
Expand Down Expand Up @@ -146,7 +151,7 @@ static int multiband_drc_init_coef(struct processing_module *mod, int16_t nch, u
/* Emphasis: collect the coef array and assign it to every channel */
emphasis = config->emp_coef;
for (ch = 0; ch < nch; ch++) {
ret = multiband_drc_eq_init_coef_ch(emphasis, &state->emphasis[ch]);
ret = multiband_drc_eq_init_coef_ch(dev, emphasis, &state->emphasis[ch]);
/* Free all previously allocated blocks in case of an error */
if (ret < 0) {
comp_err(dev, "multiband_drc_init_coef(), could not assign coeffs to ch %d",
Expand All @@ -160,7 +165,7 @@ static int multiband_drc_init_coef(struct processing_module *mod, int16_t nch, u
/* Deemphasis: collect the coef array and assign it to every channel */
deemphasis = config->deemp_coef;
for (ch = 0; ch < nch; ch++) {
ret = multiband_drc_eq_init_coef_ch(deemphasis, &state->deemphasis[ch]);
ret = multiband_drc_eq_init_coef_ch(dev, deemphasis, &state->deemphasis[ch]);
/* Free all previously allocated blocks in case of an error */
if (ret < 0) {
comp_err(dev, "multiband_drc_init_coef(), could not assign coeffs to ch %d",
Expand Down Expand Up @@ -205,10 +210,8 @@ static int multiband_drc_setup(struct processing_module *mod, int16_t channels,

/* Setup Crossover, Emphasis EQ, Deemphasis EQ, and DRC */
ret = multiband_drc_init_coef(mod, channels, rate);
if (ret < 0)
return ret;

return 0;
/* This will return 0 if no error occurred, or the negative error code. */
return ret;
}

/*
Expand Down

0 comments on commit 73fb894

Please sign in to comment.