diff --git a/src/audio/eq_fir.c b/src/audio/eq_fir.c index ed6d4db16..0a2b4e676 100644 --- a/src/audio/eq_fir.c +++ b/src/audio/eq_fir.c @@ -247,11 +247,20 @@ static struct comp_dev *eq_fir_new(struct sof_ipc_comp *comp) struct comp_data *cd; struct sof_ipc_comp_eq_fir *ipc_fir = (struct sof_ipc_comp_eq_fir *)comp; - size_t bs; + size_t bs = ipc_fir->size; int i; trace_eq("new"); + /* Check first before proceeding with dev and cd that coefficients + * blob size is sane. + */ + if (bs > SOF_EQ_FIR_MAX_SIZE) { + trace_eq_error("ens"); + trace_error_value(bs); + return NULL; + } + dev = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, COMP_SIZE(struct sof_ipc_comp_eq_fir)); if (!dev) @@ -267,19 +276,14 @@ static struct comp_dev *eq_fir_new(struct sof_ipc_comp *comp) comp_set_drvdata(dev, cd); - bs = ipc_fir->size; - if (bs > SOF_EQ_FIR_MAX_SIZE) { - rfree(dev); - rfree(cd); - return NULL; - } - cd->eq_fir_func = eq_fir_passthrough; cd->eq_fir_func_odd = eq_fir_passthrough; cd->config = NULL; - /* Allocate and make a copy of the blob and setup FIR */ - if (bs > 0) { + /* Allocate and make a copy of the coefficients blob and reset FIR. If + * the EQ is configured later in run-time the size is zero. + */ + if (bs) { cd->config = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, bs); if (!cd->config) { rfree(dev); diff --git a/src/audio/eq_iir.c b/src/audio/eq_iir.c index eca14d946..0aded733d 100644 --- a/src/audio/eq_iir.c +++ b/src/audio/eq_iir.c @@ -340,11 +340,20 @@ static struct comp_dev *eq_iir_new(struct sof_ipc_comp *comp) struct comp_data *cd; struct sof_ipc_comp_eq_iir *ipc_iir = (struct sof_ipc_comp_eq_iir *)comp; - size_t bs; + size_t bs = ipc_iir->size; int i; trace_eq("new"); + /* Check first before proceeding with dev and cd that coefficients + * blob size is sane. + */ + if (bs > SOF_EQ_IIR_MAX_SIZE) { + trace_eq_error("ens"); + trace_error_value(bs); + return NULL; + } + dev = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, COMP_SIZE(struct sof_ipc_comp_eq_iir)); if (!dev) @@ -365,15 +374,10 @@ static struct comp_dev *eq_iir_new(struct sof_ipc_comp *comp) cd->iir_delay_size = 0; cd->config = NULL; - bs = ipc_iir->size; - if (bs > SOF_EQ_IIR_MAX_SIZE) { - rfree(dev); - rfree(cd); - return NULL; - } - - /* Allocate and make a copy of the blob and setup IIR */ - if (bs > 0) { + /* Allocate and make a copy of the coefficients blob and reset IIR. If + * the EQ is configured later in run-time the size is zero. + */ + if (bs) { cd->config = rzalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, bs); if (!cd->config) { rfree(dev);