Skip to content

ASoC: SOF: sof-audio: Fix error path in sof_widget_setup_unlocked()#5798

Open
ujfalusi wants to merge 1 commit into
thesofproject:topic/sof-devfrom
ujfalusi:peter/sof/pr/widget_setup_error_fix
Open

ASoC: SOF: sof-audio: Fix error path in sof_widget_setup_unlocked()#5798
ujfalusi wants to merge 1 commit into
thesofproject:topic/sof-devfrom
ujfalusi:peter/sof/pr/widget_setup_error_fix

Conversation

@ujfalusi
Copy link
Copy Markdown
Collaborator

@ujfalusi ujfalusi commented Jun 2, 2026

If either tplg_ops->dai_config or widget_kcontrol_setup fail during widget setup we would double decrement the use_count of the widget because the sof_widget_free_unlocked() would be called twice, similarly the core_put would be invoked twice as well.

The code between pipe_widget_free and use_count_dec is done within sof_widget_free_unlocked() and we need to skip it during error handling.

The fixes tag is picked to the last change around this part of the code which is adequately old enough for backporting purposes.

Link: thesofproject/sof#10826
Fixes: 31ed8da ("ASoC: SOF: sof-audio: Modify logic for enabling/disabling topology cores")

Copilot AI review requested due to automatic review settings June 2, 2026 09:31
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes error handling in sof_widget_setup_unlocked() to prevent double-cleanup (double use_count decrement and duplicate pipeline/core teardown) when tplg_ops->dai_config() or widget_kcontrol_setup() fails during widget setup.

Changes:

  • After calling sof_widget_free_unlocked() in the widget_free: error path, jump directly to use_count_dec to avoid re-running the pipe_widget_free cleanup logic.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread sound/soc/sof/sof-audio.c Outdated
sof_widget_free_unlocked(sdev, swidget);
use_count_decremented = true;
/* sof_widget_free_unlocked already cleaned up pipe_widget/cores */
goto use_count_dec;
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.

use_count is decremented in sof_widget_free_unlocked() and we set use_count_decremented = true; above. That means swidget->use_count will not be decremented after the use_count_dec: label. Why don't we return ret here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

yes, you are right! we should just return from here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

and we can also remove the use_count_decremented as well ..

If either tplg_ops->dai_config or widget_kcontrol_setup fail during widget
setup we would double decrement the use_count of the widget because the
sof_widget_free_unlocked() would be called twice, similarly the core_put
would be invoked twice as well.

Since the use_count and core_put() is handled within the widget_free
function we need to return without falling through the pipe_widget_free
label.

The fixes tag is picked to the last change around this part of the code
which is adequately old enough for backporting purposes.

Link: thesofproject/sof#10826
Fixes: 31ed8da ("ASoC: SOF: sof-audio: Modify logic for enabling/disabling topology cores")
Signed-off-by: Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
@ujfalusi ujfalusi force-pushed the peter/sof/pr/widget_setup_error_fix branch from 7aea88b to 2c9f0c0 Compare June 3, 2026 05:43
@ujfalusi
Copy link
Copy Markdown
Collaborator Author

ujfalusi commented Jun 3, 2026

Changes since v1:

  • return right away instead of goto
  • remove the use_count_decremented variable as it is no longer needed

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.

3 participants