Skip to content

Commit 167e5b8

Browse files
singalsulgirdwood
authored andcommitted
audio: drc: add IPC-time blob validator
This patch hooks a drc blob validator into the model handler so a corrupted run-time configuration update is rejected before it can replace the working blob. Playback or capture then continues with the previously set parameters instead of being interrupted by a bad IPC. The DRC configuration is a fixed-size struct sof_drc_config, so the validator requires the IPC payload size to match exactly and the self-declared config->size to agree with it. It is installed in drc_init() when the model handler is created, so every blob swap is covered - including any received while the component is in READY - and the redundant size check that drc_prepare() used to run on the initial blob is dropped. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent 5ba08e6 commit 167e5b8

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

src/audio/drc/drc.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,20 @@ static int drc_setup(struct processing_module *mod, uint16_t channels, uint32_t
139139
return drc_set_pre_delay_time(&cd->state, cd->config->params.pre_delay_time, rate);
140140
}
141141

142+
static int drc_validator(struct comp_dev *dev, void *new_data, uint32_t new_data_size)
143+
{
144+
struct sof_drc_config *config = new_data;
145+
146+
if (new_data_size != sizeof(struct sof_drc_config) ||
147+
new_data_size != config->size) {
148+
comp_err(dev, "invalid configuration blob, size %u, expected %zu",
149+
new_data_size, sizeof(struct sof_drc_config));
150+
return -EINVAL;
151+
}
152+
153+
return 0;
154+
}
155+
142156
/*
143157
* End of DRC setup code. Next the standard component methods.
144158
*/
@@ -168,6 +182,11 @@ __cold static int drc_init(struct processing_module *mod)
168182
goto cd_fail;
169183
}
170184

185+
/* Reject malformed blobs at IPC time so a bad run-time update cannot
186+
* replace the working configuration.
187+
*/
188+
comp_data_blob_set_validator(cd->model_handler, drc_validator);
189+
171190
drc_reset_state(mod, &cd->state);
172191

173192
/* Initialize DRC to enabled. If defined by topology, a control may set
@@ -326,7 +345,6 @@ static int drc_prepare(struct processing_module *mod,
326345
struct drc_comp_data *cd = module_get_private_data(mod);
327346
struct comp_buffer *sourceb, *sinkb;
328347
struct comp_dev *dev = mod->dev;
329-
size_t data_size;
330348
int channels;
331349
int rate;
332350
int ret;
@@ -352,11 +370,9 @@ static int drc_prepare(struct processing_module *mod,
352370

353371
/* Initialize DRC */
354372
comp_info(dev, "source_format=%d", cd->source_format);
355-
cd->config = comp_get_data_blob(cd->model_handler, &data_size, NULL);
356-
/* the blob is dereferenced as a struct sof_drc_config below and in
357-
* drc_setup(), so require it to be at least that large
358-
*/
359-
if (cd->config && data_size >= sizeof(struct sof_drc_config)) {
373+
cd->config = comp_get_data_blob(cd->model_handler, NULL, NULL);
374+
375+
if (cd->config) {
360376
ret = drc_setup(mod, channels, rate);
361377
if (ret < 0) {
362378
comp_err(dev, "error: drc_setup failed.");

0 commit comments

Comments
 (0)