Skip to content

Commit 87fa65d

Browse files
committed
Audio: Remove bytes control blob initialize from module init()
The pass of bytes control blob from topology in init() was used in some early IPC3 kernels but with add of support for multiple controls blob it was changed to use normal controls IPC. With IPC4 the module configuration data is not for ALSA controls while some modules still handled it as such. If a topology does not contain a blob to initialize the control, an invalid blob is attempted to be used in prepare(). The prepare() then fails with invalid blob detected while the modules would normally result to pass-through mode when not configured. In addition to code removal a check is added to prepare() for the data_size from comp_get_data_blob() to ensure the configuration data is not zero size. This patch fixes the similar issue in crossover, dcblock, drc, fir, iir, mfcc, multiband-drc, and tdfb. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent 0210345 commit 87fa65d

File tree

8 files changed

+37
-189
lines changed

8 files changed

+37
-189
lines changed

src/audio/crossover/crossover.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -296,19 +296,10 @@ static int crossover_init(struct processing_module *mod)
296296
struct module_data *md = &mod->priv;
297297
struct comp_dev *dev = mod->dev;
298298
struct comp_data *cd;
299-
const struct module_config *ipc_crossover = &md->cfg;
300-
size_t bs = ipc_crossover->size;
301299
int ret;
302300

303301
comp_info(dev, "entry");
304302

305-
/* Check that the coefficients blob size is sane */
306-
if (bs > SOF_CROSSOVER_MAX_SIZE) {
307-
comp_err(dev, "blob size (%d) exceeds maximum allowed size (%i)",
308-
bs, SOF_CROSSOVER_MAX_SIZE);
309-
return -ENOMEM;
310-
}
311-
312303
cd = mod_zalloc(mod, sizeof(*cd));
313304
if (!cd)
314305
return -ENOMEM;
@@ -323,13 +314,6 @@ static int crossover_init(struct processing_module *mod)
323314
goto cd_fail;
324315
}
325316

326-
/* Get configuration data and reset Crossover state */
327-
ret = comp_init_data_blob(cd->model_handler, bs, ipc_crossover->data);
328-
if (ret < 0) {
329-
comp_err(dev, "comp_init_data_blob() failed.");
330-
goto cd_fail;
331-
}
332-
333317
ret = crossover_output_pin_init(mod);
334318
if (ret < 0) {
335319
comp_err(dev, "failed.");
@@ -527,6 +511,7 @@ static int crossover_prepare(struct processing_module *mod,
527511
struct comp_data *cd = module_get_private_data(mod);
528512
struct comp_dev *dev = mod->dev;
529513
struct comp_buffer *source, *sink;
514+
size_t data_size;
530515
int channels;
531516

532517
comp_info(dev, "entry");
@@ -558,10 +543,11 @@ static int crossover_prepare(struct processing_module *mod,
558543
comp_info(dev, "source_format=%d, sink_formats=%d, nch=%d",
559544
cd->source_format, cd->source_format, channels);
560545

561-
cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL);
546+
cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL);
562547

563548
/* Initialize Crossover */
564-
if (cd->config && crossover_validate_config(mod, cd->config) < 0) {
549+
if (cd->config &&
550+
(!data_size || crossover_validate_config(mod, cd->config) < 0)) {
565551
/* If config is invalid then delete it */
566552
comp_err(dev, "invalid binary config format");
567553
crossover_free_config(&cd->config);

src/audio/dcblock/dcblock.c

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ static int dcblock_init(struct processing_module *mod)
8080
{
8181
struct module_data *md = &mod->priv;
8282
struct comp_dev *dev = mod->dev;
83-
struct module_config *ipc_dcblock = &md->cfg;
8483
struct comp_data *cd;
85-
size_t bs = ipc_dcblock->size;
86-
int ret;
8784

8885
comp_info(dev, "entry");
8986

@@ -98,24 +95,11 @@ static int dcblock_init(struct processing_module *mod)
9895
cd->model_handler = comp_data_blob_handler_new(dev);
9996
if (!cd->model_handler) {
10097
comp_err(dev, "comp_data_blob_handler_new() failed.");
101-
ret = -ENOMEM;
102-
goto err_cd;
103-
}
104-
105-
ret = comp_init_data_blob(cd->model_handler, bs, ipc_dcblock->data);
106-
if (ret < 0) {
107-
comp_err(dev, "comp_init_data_blob() failed with error: %d", ret);
108-
goto err_model_cd;
98+
rfree(cd);
99+
return -ENOMEM;
109100
}
110101

111102
return 0;
112-
113-
err_model_cd:
114-
comp_data_blob_handler_free(cd->model_handler);
115-
116-
err_cd:
117-
rfree(cd);
118-
return ret;
119103
}
120104

121105
/**
@@ -190,6 +174,7 @@ static int dcblock_prepare(struct processing_module *mod,
190174
struct comp_data *cd = module_get_private_data(mod);
191175
struct comp_buffer *sourceb, *sinkb;
192176
struct comp_dev *dev = mod->dev;
177+
size_t data_size;
193178

194179
comp_info(dev, "entry");
195180

@@ -219,8 +204,8 @@ static int dcblock_prepare(struct processing_module *mod,
219204
comp_info(mod->dev, "source_format=%d, sink_format=%d",
220205
cd->source_format, cd->sink_format);
221206

222-
cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL);
223-
if (cd->config)
207+
cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL);
208+
if (cd->config && data_size > 0)
224209
dcblock_copy_coefficients(mod);
225210
else
226211
dcblock_set_passthrough(mod);

src/audio/drc/drc.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,13 @@ __cold static int drc_init(struct processing_module *mod)
147147
{
148148
struct module_data *md = &mod->priv;
149149
struct comp_dev *dev = mod->dev;
150-
struct module_config *cfg = &md->cfg;
151150
struct drc_comp_data *cd;
152-
size_t bs = cfg->size;
153151
int ret;
154152

155153
assert_can_be_cold();
156154

157155
comp_info(dev, "entry");
158156

159-
/* Check first before proceeding with dev and cd that coefficients
160-
* blob size is sane.
161-
*/
162-
if (bs > SOF_DRC_MAX_SIZE) {
163-
comp_err(dev, "error: configuration blob size = %u > %d",
164-
bs, SOF_DRC_MAX_SIZE);
165-
return -EINVAL;
166-
}
167-
168157
cd = mod_zalloc(mod, sizeof(*cd));
169158
if (!cd)
170159
return -ENOMEM;
@@ -179,13 +168,6 @@ __cold static int drc_init(struct processing_module *mod)
179168
goto cd_fail;
180169
}
181170

182-
/* Get configuration data and reset DRC state */
183-
ret = comp_init_data_blob(cd->model_handler, bs, cfg->data);
184-
if (ret < 0) {
185-
comp_err(dev, "comp_init_data_blob() failed.");
186-
goto cd_fail;
187-
}
188-
189171
drc_reset_state(mod, &cd->state);
190172

191173
/* Initialize DRC to enabled. If defined by topology, a control may set
@@ -344,6 +326,7 @@ static int drc_prepare(struct processing_module *mod,
344326
struct drc_comp_data *cd = module_get_private_data(mod);
345327
struct comp_buffer *sourceb, *sinkb;
346328
struct comp_dev *dev = mod->dev;
329+
size_t data_size;
347330
int channels;
348331
int rate;
349332
int ret;
@@ -369,8 +352,8 @@ static int drc_prepare(struct processing_module *mod,
369352

370353
/* Initialize DRC */
371354
comp_info(dev, "source_format=%d", cd->source_format);
372-
cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL);
373-
if (cd->config) {
355+
cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL);
356+
if (cd->config && data_size > 0) {
374357
ret = drc_setup(mod, channels, rate);
375358
if (ret < 0) {
376359
comp_err(dev, "error: drc_setup failed.");

src/audio/eq_fir/eq_fir.c

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -247,23 +247,11 @@ static int eq_fir_init(struct processing_module *mod)
247247
{
248248
struct module_data *md = &mod->priv;
249249
struct comp_dev *dev = mod->dev;
250-
struct module_config *cfg = &md->cfg;
251250
struct comp_data *cd = NULL;
252-
size_t bs = cfg->size;
253251
int i;
254-
int ret;
255252

256253
comp_info(dev, "entry");
257254

258-
/* Check first before proceeding with dev and cd that coefficients
259-
* blob size is sane.
260-
*/
261-
if (bs > SOF_EQ_FIR_MAX_SIZE) {
262-
comp_err(dev, "coefficients blob size = %zu > SOF_EQ_FIR_MAX_SIZE",
263-
bs);
264-
return -EINVAL;
265-
}
266-
267255
cd = mod_zalloc(mod, sizeof(*cd));
268256
if (!cd)
269257
return -ENOMEM;
@@ -277,31 +265,16 @@ static int eq_fir_init(struct processing_module *mod)
277265
cd->model_handler = mod_data_blob_handler_new(mod);
278266
if (!cd->model_handler) {
279267
comp_err(dev, "mod_data_blob_handler_new() failed.");
280-
ret = -ENOMEM;
281-
goto err;
268+
mod_free(mod, cd);
269+
return -ENOMEM;
282270
}
283271

284272
md->private = cd;
285273

286-
/* Allocate and make a copy of the coefficients blob and reset FIR. If
287-
* the EQ is configured later in run-time the size is zero.
288-
*/
289-
ret = comp_init_data_blob(cd->model_handler, bs, cfg->init_data);
290-
if (ret < 0) {
291-
comp_err(dev, "comp_init_data_blob() failed.");
292-
goto err_init;
293-
}
294-
295274
for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
296275
fir_reset(&cd->fir[i]);
297276

298277
return 0;
299-
300-
err_init:
301-
mod_data_blob_handler_free(mod, cd->model_handler);
302-
err:
303-
mod_free(mod, cd);
304-
return ret;
305278
}
306279

307280
static int eq_fir_free(struct processing_module *mod)
@@ -413,6 +386,7 @@ static int eq_fir_prepare(struct processing_module *mod,
413386
int channels;
414387
enum sof_ipc_frame frame_fmt;
415388
int ret = 0;
389+
size_t data_size;
416390

417391
comp_dbg(dev, "entry");
418392

@@ -435,8 +409,8 @@ static int eq_fir_prepare(struct processing_module *mod,
435409
frame_fmt = audio_stream_get_frm_fmt(&sourceb->stream);
436410

437411
cd->eq_fir_func = eq_fir_passthrough;
438-
cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL);
439-
if (cd->config) {
412+
cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL);
413+
if (cd->config && data_size > 0) {
440414
ret = eq_fir_setup(mod, channels);
441415
if (ret < 0)
442416
comp_err(dev, "eq_fir_setup failed.");

src/audio/eq_iir/eq_iir.c

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,11 @@ static int eq_iir_init(struct processing_module *mod)
4444
{
4545
struct module_data *md = &mod->priv;
4646
struct comp_dev *dev = mod->dev;
47-
struct module_config *cfg = &md->cfg;
4847
struct comp_data *cd;
49-
size_t bs = cfg->size;
50-
int i, ret;
48+
int i;
5149

5250
comp_info(dev, "entry");
5351

54-
/* Check first before proceeding with dev and cd that coefficients blob size is sane */
55-
if (bs > SOF_EQ_IIR_MAX_SIZE) {
56-
comp_err(dev, "coefficients blob size %zu exceeds maximum", bs);
57-
return -EINVAL;
58-
}
59-
6052
cd = mod_zalloc(mod, sizeof(*cd));
6153
if (!cd)
6254
return -ENOMEM;
@@ -67,28 +59,14 @@ static int eq_iir_init(struct processing_module *mod)
6759
cd->model_handler = mod_data_blob_handler_new(mod);
6860
if (!cd->model_handler) {
6961
comp_err(dev, "mod_data_blob_handler_new() failed.");
70-
ret = -ENOMEM;
71-
goto err;
72-
}
73-
74-
/* Allocate and make a copy of the coefficients blob and reset IIR. If
75-
* the EQ is configured later in run-time the size is zero.
76-
*/
77-
ret = comp_init_data_blob(cd->model_handler, bs, cfg->data);
78-
if (ret < 0) {
79-
comp_err(dev, "comp_init_data_blob() failed with error: %d", ret);
80-
goto err;
62+
mod_free(mod, cd);
63+
return -ENOMEM;
8164
}
8265

8366
for (i = 0; i < PLATFORM_MAX_CHANNELS; i++)
8467
iir_reset_df1(&cd->iir[i]);
8568

8669
return 0;
87-
88-
err:
89-
mod_data_blob_handler_free(mod, cd->model_handler);
90-
mod_free(mod, cd);
91-
return ret;
9270
}
9371

9472
static int eq_iir_free(struct processing_module *mod)
@@ -180,6 +158,7 @@ static int eq_iir_prepare(struct processing_module *mod,
180158
struct comp_dev *dev = mod->dev;
181159
enum sof_ipc_frame source_format;
182160
enum sof_ipc_frame sink_format;
161+
size_t data_size;
183162
int channels;
184163
int ret = 0;
185164

@@ -204,7 +183,7 @@ static int eq_iir_prepare(struct processing_module *mod,
204183
source_format = audio_stream_get_frm_fmt(&sourceb->stream);
205184
sink_format = audio_stream_get_frm_fmt(&sinkb->stream);
206185

207-
cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL);
186+
cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL);
208187

209188
/* Initialize EQ */
210189
comp_info(dev, "source_format=%d, sink_format=%d",
@@ -213,7 +192,7 @@ static int eq_iir_prepare(struct processing_module *mod,
213192
eq_iir_set_passthrough_func(cd, source_format, sink_format);
214193

215194
/* Initialize EQ */
216-
if (cd->config) {
195+
if (cd->config && data_size > 0) {
217196
ret = eq_iir_new_blob(mod, source_format, sink_format, channels);
218197
if (ret)
219198
return ret;

src/audio/mfcc/mfcc.c

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,10 @@ static int mfcc_init(struct processing_module *mod)
7272
{
7373
struct module_data *md = &mod->priv;
7474
struct comp_dev *dev = mod->dev;
75-
struct module_config *cfg = &md->cfg;
7675
struct mfcc_comp_data *cd = NULL;
77-
size_t bs = cfg->size;
78-
int ret;
7976

8077
comp_info(dev, "entry");
8178

82-
/* Check first that configuration blob size is sane */
83-
if (bs > SOF_MFCC_CONFIG_MAX_SIZE) {
84-
comp_err(dev, "error: configuration blob size %zu exceeds %d",
85-
bs, SOF_MFCC_CONFIG_MAX_SIZE);
86-
return -EINVAL;
87-
}
88-
8979
cd = mod_zalloc(mod, sizeof(*cd));
9080
if (!cd)
9181
return -ENOMEM;
@@ -95,25 +85,11 @@ static int mfcc_init(struct processing_module *mod)
9585
cd->model_handler = mod_data_blob_handler_new(mod);
9686
if (!cd->model_handler) {
9787
comp_err(dev, "comp_data_blob_handler_new() failed.");
98-
ret = -ENOMEM;
99-
goto err;
100-
}
101-
102-
/* Get configuration data */
103-
ret = comp_init_data_blob(cd->model_handler, bs, cfg->init_data);
104-
if (ret < 0) {
105-
comp_err(mod->dev, "comp_init_data_blob() failed.");
106-
goto err_init;
88+
mod_free(mod, cd);
89+
return -ENOMEM;
10790
}
10891

10992
return 0;
110-
111-
err_init:
112-
comp_data_blob_handler_free(cd->model_handler);
113-
114-
err:
115-
mod_free(mod, cd);
116-
return ret;
11793
}
11894

11995
static int mfcc_free(struct processing_module *mod)
@@ -183,6 +159,7 @@ static int mfcc_prepare(struct processing_module *mod,
183159
struct comp_dev *dev = mod->dev;
184160
enum sof_ipc_frame source_format;
185161
enum sof_ipc_frame sink_format;
162+
size_t data_size;
186163
uint32_t sink_period_bytes;
187164
int ret;
188165

@@ -211,10 +188,10 @@ static int mfcc_prepare(struct processing_module *mod,
211188
goto err;
212189
}
213190

214-
cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL);
191+
cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL);
215192

216193
/* Initialize MFCC, max_frames is set to dev->frames + 4 */
217-
if (cd->config) {
194+
if (cd->config && data_size > 0) {
218195
ret = mfcc_setup(mod, dev->frames + 4, audio_stream_get_rate(&sourceb->stream),
219196
audio_stream_get_channels(&sourceb->stream));
220197
if (ret < 0) {

0 commit comments

Comments
 (0)