-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ASoC: SOF: Intel: test w before processing the params_stream callback #5250
Conversation
if (!w) { | ||
dev_err(cpu_dai->dev, | ||
"cpu dai widget not found, check amp link num in the topology\n"); | ||
return -EINVAL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no way to catch this during probe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can catch this during probe since we need substream->stream
. What do you think? @ranj063
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's one possibility of making sure that all cpu DAI's associated with all runtimes in the card have their respective stream widgets set. What we can do is in the topology complete op, we can iterate though all of the rtd's and check if they're set and fail if they aren't. Worth a try. Something like this in sof_complete()
struct snd_soc_card *card = scomp->card;
list_for_each_entry(rtd, &card->rtd_list, list)
for_each_rtd_cpu_dais(rtd, i, cpu_dai)
if (!snd_soc_dai_get_widget(cpu_dai, stream))
return -EINVAL;
A CPU DAI must have atleast the playback/capture widget set. so you'd have to check both directions above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I can add
list_for_each_entry(rtd, &card->rtd_list, list)
for_each_rtd_cpu_dais(rtd, i, cpu_dai)
if (!snd_soc_dai_get_widget(cpu_dai, SNDRV_PCM_STREAM_PLAYBACK) &&
!snd_soc_dai_get_widget(cpu_dai, SNDRV_PCM_STREAM_CAPTURE)) {
dev_err(sdev->dev, "no associated widgets for dai %s\n",
cpu_dai->name);
return -EINVAL;
}
in sof_complete().
However, it will not return error if a dai has both directions and one direction isn't associated with a widget.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so if we know what directions the CPU DAI has set, can we not check both or either based on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main issue is that the dai links may not always be used by the topology. I.e. topology could be a subset of the dai links. In that case the cpu dai will not associate with any widget and it is still valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair enough. this change looks good then
sound/soc/sof/intel/hda.c
Outdated
dev_err(dev, "%s: widget not found, check amp link num in the topology\n", | ||
__func__); | ||
return -EINVAL; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bardliao, the w
is unused here, do we really need this check added to this specific function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking here is to be consistent as sdw_params_stream(). Both sdw_params_stream() and sdw_ace2x_params_stream() are .params_stream callback. We can also check in sdw_hda_dai_hw_params(). What do you prefer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imho you should check for NULL pointer where it can cause issues. You will catch this problem anyways, but if you insist of doing it here, then do a simple
if (!snd_soc_dai_get_widget(params_data->dai, params_data->substream->stream)) {
}
perhaps as forward looking check, but again, in this function the w
is not used, so why check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, so yes, you should check in sdw_hda_dai_hw_params()
, not here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated, thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we say in the commit message why aggregated amps are special here so that upstream reviewers understand why we have to be more cautious. Thanks !
…id during params Each cpu DAI should associate with a widget. However, the topology might not create the right number of DAI widgets for aggregated amps. And it will cause NULL pointer deference. Check that the DAI widget associated with the CPU DAI is valid to prevent NULL pointer deference due to missing DAI widgets in topologies with aggregated amps. Signed-off-by: Bard Liao <[email protected]>
Commit message updated. |
The DAI widget is set by the topology. And it will not be set if the widget is not defined in the topology. The case happens if the topology doesn't provide enough DAI widgets of the amp in the amp aggregation case.
Test w to report the error and avoid kernel NULL pointer dereference.