Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions src/audio/selector/selector.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,55 @@ static int selector_ctrl_set_data(struct comp_dev *dev,
case SOF_CTRL_CMD_BINARY:
comp_dbg(dev, "SOF_CTRL_CMD_BINARY");

if (cdata->data->size < sizeof(struct sof_sel_config)) {
comp_err(dev, "invalid config blob size %u", cdata->data->size);
return -EINVAL;
}

cfg = (struct sof_sel_config *)
ASSUME_ALIGNED(&cdata->data->data, 4);

/*
* The config validated at .params() time can be replaced here at
* runtime, so re-validate the new channel counts and selected
* channel before accepting them; otherwise an out-of-range value
* later overflows the channel coefficient table during process().
*/
switch (cfg->in_channels_count) {
case 0:
case SEL_SOURCE_2CH:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case SEL_SOURCE_4CH:
break;
default:
comp_err(dev, "invalid in_channels_count %u",
cfg->in_channels_count);
return -EINVAL;
}

switch (cfg->out_channels_count) {
case 0:
case SEL_SINK_1CH:
case SEL_SINK_2CH:
case SEL_SINK_4CH:
break;
default:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also 5.1 and 7.1 sinks

comp_err(dev, "invalid out_channels_count %u",
cfg->out_channels_count);
return -EINVAL;
}
Comment on lines +255 to +276

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 isn't a "no change" sentinel here — it's a valid configuration meaning "derive the channel count from the stream at runtime". See selector_verify_params(): out_channels = cd->config.out_channels_count ? cd->config.out_channels_count : audio_stream_get_channels(...) (same for in). So accepting and storing 0 is correct; the effective count is resolved (and re-validated) at .params() time.

Comment on lines +255 to +276

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two paths validate different things, which is why I didn't share code: selector_verify_params() validates the effective in/out channel counts at .params() time — deriving them from the stream when the config value is 0 and checking sel_channel against the actual runtime channel count. This handler validates the raw config fields before they're stored (accepted values, and sel_channel against the fixed input count). A shared helper would only cover the accepted-value switches and would mean restructuring verify_params to validate raw values before deriving. Happy to extract one if you'd prefer that, but kept them separate to avoid changing the prepare-time logic.


/* sel_channel indexes the source channels: bound it by the
* absolute maximum, and (when the input count is fixed, i.e.
* non-zero) by the configured input channel count too
*/
if (cfg->sel_channel >= SEL_SOURCE_CHANNELS_MAX ||
(cfg->in_channels_count &&
cfg->sel_channel >= cfg->in_channels_count)) {
comp_err(dev, "invalid sel_channel %u (in_channels_count %u)",
cfg->sel_channel, cfg->in_channels_count);
return -EINVAL;
}

/* Just set the configuration */
cd->config.in_channels_count = cfg->in_channels_count;
cd->config.out_channels_count = cfg->out_channels_count;
Comment on lines 290 to 292

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 isn't a "no change" sentinel here — it's a valid configuration meaning "derive the channel count from the stream at runtime". See selector_verify_params(): out_channels = cd->config.out_channels_count ? cd->config.out_channels_count : audio_stream_get_channels(...) (same for in). So accepting and storing 0 is correct; the effective count is resolved (and re-validated) at .params() time.

Expand Down
Loading