mirror of https://github.com/thesofproject/sof.git
EQ: Check in new() coefficient blob size before allocating dev and cd
This patch simplifies new() function code and avoids unnecessary allocation of component device and data resources if the the coefficient blob is rejected due to size. The change is identical for FIR and IIR EQs. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
This commit is contained in:
parent
ce7f99be29
commit
323c55ae8d
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue