Skip to content
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

Merged
merged 1 commit into from
Nov 26, 2024

Conversation

bardliao
Copy link
Collaborator

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.

sound/soc/sof/intel/hda-dai.c Show resolved Hide resolved
if (!w) {
dev_err(cpu_dai->dev,
"cpu dai widget not found, check amp link num in the topology\n");
return -EINVAL;
Copy link
Collaborator

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?

Copy link
Collaborator Author

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

Copy link
Collaborator

@ranj063 ranj063 Nov 21, 2024

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

Copy link
Collaborator Author

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.

Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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

ujfalusi
ujfalusi previously approved these changes Nov 21, 2024
dev_err(dev, "%s: widget not found, check amp link num in the topology\n",
__func__);
return -EINVAL;
}
Copy link
Collaborator

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?

Copy link
Collaborator Author

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?

Copy link
Collaborator

@ujfalusi ujfalusi Nov 25, 2024

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?

Copy link
Collaborator

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated, thanks.

Copy link
Member

@lgirdwood lgirdwood left a 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]>
@bardliao
Copy link
Collaborator Author

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 !

Commit message updated.

@ranj063 ranj063 merged commit 414dc95 into thesofproject:topic/sof-dev Nov 26, 2024
12 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants