From dcb185a78c994119e9b65563ac99665cecab2de3 Mon Sep 17 00:00:00 2001 From: Bartosz Kokoszko Date: Fri, 19 Jun 2020 15:15:12 +0200 Subject: [PATCH] comp: return 0 in data size 0 case in comp_set_model In comp_set_model() function, when required size is equal to 0, we should not allocate memory and just return 0. Signed-off-by: Bartosz Kokoszko --- src/audio/component.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/audio/component.c b/src/audio/component.c index e6f89e2be..eeb060670 100644 --- a/src/audio/component.c +++ b/src/audio/component.c @@ -341,11 +341,11 @@ void comp_free_model_data(struct comp_dev *dev, struct comp_model_data *model) int comp_alloc_model_data(struct comp_dev *dev, struct comp_model_data *model, uint32_t size) { + comp_free_model_data(dev, model); + if (!size) return 0; - comp_free_model_data(dev, model); - model->data = rballoc(0, SOF_MEM_CAPS_RAM, size); if (!model->data) { @@ -376,7 +376,10 @@ int comp_set_model(struct comp_dev *dev, struct comp_model_data *model, */ if (!cdata->msg_index) { ret = comp_alloc_model_data(dev, model, cdata->data->size); - if (ret < 0) + /* in case when required model size is equal to zero we do not + * allocate memory and should just return 0 + */ + if (ret < 0 || !cdata->data->size) return ret; }