All of lore.kernel.org
 help / color / mirror / Atom feed
* [RESEND PATCH] ASoC: core: Exit all links before removing their components
@ 2022-10-27  8:58 Cezary Rojewski
  2022-11-18 10:56 ` Cezary Rojewski
  2022-11-20 11:56 ` Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Cezary Rojewski @ 2022-10-27  8:58 UTC (permalink / raw)
  To: alsa-devel, broonie
  Cc: Cezary Rojewski, pierre-louis.bossart, tiwai, hdegoede,
	amadeuszx.slawinski

Flows leading to link->init() and link->exit() are not symmetric.
Currently the relevant part of card probe sequence goes as:

	for_each_card_rtds(card, rtd)
		for_each_rtd_components(rtd, i, component)
			component->probe()
	for_each_card_rtds(card, rtd)
		for_each_rtd_dais(rtd, i, dai)
			dai->probe()
	for_each_card_rtds(card, rtd)
		rtd->init()

On the other side, equivalent remove sequence goes as:

	for_each_card_rtds(card, rtd)
		for_each_rtd_dais(rtd, i, dai)
			dai->remove()
	for_each_card_rtds(card, rtd)
		for_each_rtd_components(rtd, i, component)
			component->remove()
	for_each_card_rtds(card, rtd)
		rtd->exit()

what can lead to errors as link->exit() may still operate on resources
owned by its components despite the probability of them being freed
during the component->remove().

This change modifies the remove sequence to:

	for_each_card_rtds(card, rtd)
		rtd->exit()
	for_each_card_rtds(card, rtd)
		for_each_rtd_dais(rtd, i, dai)
			dai->remove()
	for_each_card_rtds(card, rtd)
		for_each_rtd_components(rtd, i, component)
			component->remove()

so code found in link->exit() is safe to touch any component stuff as
component->remove() has not been called yet.

Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
Reviewed-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
---

Original review for v1:
https://lore.kernel.org/alsa-devel/20220621115758.3154933-1-cezary.rojewski@intel.com/

 sound/soc/soc-core.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 4a3fca50a536..638e781df3b0 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -935,9 +935,6 @@ void snd_soc_remove_pcm_runtime(struct snd_soc_card *card,
 {
 	lockdep_assert_held(&client_mutex);
 
-	/* release machine specific resources */
-	snd_soc_link_exit(rtd);
-
 	/*
 	 * Notify the machine driver for extra destruction
 	 */
@@ -1888,6 +1885,9 @@ static void soc_cleanup_card_resources(struct snd_soc_card *card)
 
 	snd_soc_dapm_shutdown(card);
 
+	/* release machine specific resources */
+	for_each_card_rtds(card, rtd)
+		snd_soc_link_exit(rtd);
 	/* remove and free each DAI */
 	soc_remove_link_dais(card);
 	soc_remove_link_components(card);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RESEND PATCH] ASoC: core: Exit all links before removing their components
  2022-10-27  8:58 [RESEND PATCH] ASoC: core: Exit all links before removing their components Cezary Rojewski
@ 2022-11-18 10:56 ` Cezary Rojewski
  2022-11-20 11:56 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Cezary Rojewski @ 2022-11-18 10:56 UTC (permalink / raw)
  To: alsa-devel, broonie
  Cc: pierre-louis.bossart, hdegoede, amadeuszx.slawinski, tiwai

On 2022-10-27 10:58 AM, Cezary Rojewski wrote:
> Flows leading to link->init() and link->exit() are not symmetric.
> Currently the relevant part of card probe sequence goes as:
> 
> 	for_each_card_rtds(card, rtd)
> 		for_each_rtd_components(rtd, i, component)
> 			component->probe()
> 	for_each_card_rtds(card, rtd)
> 		for_each_rtd_dais(rtd, i, dai)
> 			dai->probe()
> 	for_each_card_rtds(card, rtd)
> 		rtd->init()
> 
> On the other side, equivalent remove sequence goes as:
> 
> 	for_each_card_rtds(card, rtd)
> 		for_each_rtd_dais(rtd, i, dai)
> 			dai->remove()
> 	for_each_card_rtds(card, rtd)
> 		for_each_rtd_components(rtd, i, component)
> 			component->remove()
> 	for_each_card_rtds(card, rtd)
> 		rtd->exit()
> 
> what can lead to errors as link->exit() may still operate on resources
> owned by its components despite the probability of them being freed
> during the component->remove().
> 
> This change modifies the remove sequence to:
> 
> 	for_each_card_rtds(card, rtd)
> 		rtd->exit()
> 	for_each_card_rtds(card, rtd)
> 		for_each_rtd_dais(rtd, i, dai)
> 			dai->remove()
> 	for_each_card_rtds(card, rtd)
> 		for_each_rtd_components(rtd, i, component)
> 			component->remove()
> 
> so code found in link->exit() is safe to touch any component stuff as
> component->remove() has not been called yet.


As this is connected (and is a dependency) for some jack-handler 
refactoring in Intel boards, perhaps it will be better if I send this 
patch as part of a series? Lacks some context.


Regards,
Czarek

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RESEND PATCH] ASoC: core: Exit all links before removing their components
  2022-10-27  8:58 [RESEND PATCH] ASoC: core: Exit all links before removing their components Cezary Rojewski
  2022-11-18 10:56 ` Cezary Rojewski
@ 2022-11-20 11:56 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2022-11-20 11:56 UTC (permalink / raw)
  To: Cezary Rojewski, alsa-devel
  Cc: hdegoede, amadeuszx.slawinski, pierre-louis.bossart, tiwai

On Thu, 27 Oct 2022 10:58:40 +0200, Cezary Rojewski wrote:
> Flows leading to link->init() and link->exit() are not symmetric.
> Currently the relevant part of card probe sequence goes as:
> 
> 	for_each_card_rtds(card, rtd)
> 		for_each_rtd_components(rtd, i, component)
> 			component->probe()
> 	for_each_card_rtds(card, rtd)
> 		for_each_rtd_dais(rtd, i, dai)
> 			dai->probe()
> 	for_each_card_rtds(card, rtd)
> 		rtd->init()
> 
> [...]

Applied to

   broonie/sound.git for-next

Thanks!

[1/1] ASoC: core: Exit all links before removing their components
      commit: c7eb967d70446971413061effca3226578cb4dab

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-20 11:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-27  8:58 [RESEND PATCH] ASoC: core: Exit all links before removing their components Cezary Rojewski
2022-11-18 10:56 ` Cezary Rojewski
2022-11-20 11:56 ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.