Skip to contentSkip to conversation

ASoC: soc-core: Don't fail if device_link could not be created

PATCH In review Richard Fitzgerald 2 participants 2 messages Jun 23 – Jun 24

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: soc-core: Don't fail if device_link could not be created

If device_link_add() fails in snd_soc_bind_card() just skip that driver pair and carry on.

This means that ASoC must now keep track of which components it was able to device_link to the card->dev. The new card_device_link member of struct snd_soc_component is non-NULL if a device_link exists.

The intent of the device link is to ensure that the machine driver system-suspends before the component drivers, to prevent ASoC suspend attempting to reconfigure a driver that has already suspended.

It isn't possible to create this device link if the machine driver is a parent of the component driver or already has a device_link in the opposite direction. In this case skip the link. A warn is placed in kernel log since this might indicate a genuine design problem with those two drivers (this can be downgraded to dbg in future when people are happy that all these special drivers correctly handle their reversed shutdown order).

---
 include/sound/soc-component.h |  4 ++++
 sound/soc/soc-core.c          | 35 +++++++++++++++--------------------
 2 files changed, 19 insertions(+), 20 deletions(-)
include/sound/soc-component.h +4 -0
index 11bc9527653f..aa423865dbe7 100644
@@ -10,6 +10,8 @@
 
 #include <sound/soc.h>
 
+struct device_link;
+
 /*
  * Component probe and remove ordering levels for components with runtime
  * dependencies.
@@ -216,6 +218,8 @@ struct snd_soc_component {
 	struct list_head card_aux_list; /* for auxiliary bound components */
 	struct list_head card_list;
 
+	struct device_link *card_device_link;
+
 	const struct snd_soc_component_driver *driver;
 
 	struct list_head dai_list;
sound/soc/soc-core.c +15 -20
index 86b6c752a56b..7817beea5b3b 100644
@@ -1980,19 +1980,15 @@ static void soc_cleanup_card_resources(struct snd_soc_card *card)
 	}
 }
 
-static void snd_soc_remove_device_links(struct snd_soc_card *card,
-					struct snd_soc_component *stop_at)
+static void snd_soc_remove_device_links(struct snd_soc_card *card)
 {
 	struct snd_soc_component *component;
 
 	for_each_card_components(card, component) {
-		if (card->dev == component->dev)
-			continue;
-
-		device_link_remove(card->dev, component->dev);
-
-		if (component == stop_at)
-			return;
+		if (component->card_device_link) {
+			device_link_del(component->card_device_link);
+			component->card_device_link = NULL;
+		}
 	}
 }
 
@@ -2001,7 +1997,7 @@ static void snd_soc_unbind_card(struct snd_soc_card *card)
 	if (snd_soc_card_is_instantiated(card)) {
 		card->instantiated = false;
 
-		snd_soc_remove_device_links(card, NULL);
+		snd_soc_remove_device_links(card);
 
 		soc_cleanup_card_resources(card);
 	}
@@ -2012,7 +2008,6 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
 	struct snd_soc_pcm_runtime *rtd;
 	struct snd_soc_component *component;
 	struct snd_soc_dapm_context *dapm = snd_soc_card_to_dapm(card);
-	struct snd_soc_component *last_devlinked_component = NULL;
 	int ret;
 
 	snd_soc_card_mutex_lock_root(card);
@@ -2141,19 +2136,21 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
 	 * Add device_link from card to component so that system_suspend
 	 * will be done in the correct order. The card must suspend first
 	 * to stop audio activity before the components suspend.
+	 *
+	 * If a driver pair already have a link in the opposite direction
+	 * they must manage their own suspend order.
 	 */
 	for_each_card_components(card, component) {
 		if (card->dev == component->dev)
 			continue;
 
-		if (!device_link_add(card->dev, component->dev, DL_FLAG_STATELESS)) {
-			dev_warn(card->dev, "Failed to create device link to %s\n",
+		component->card_device_link = device_link_add(card->dev,
+							      component->dev,
+							      DL_FLAG_STATELESS);
+		if (!component->card_device_link) {
+			dev_warn(card->dev, "Could not create device link to %s\n",
 				 dev_name(component->dev));
-			ret = -EINVAL;
-			goto probe_end;
 		}
-
-		last_devlinked_component = component;
 	}
 
 	ret = snd_soc_card_late_probe(card);
@@ -2185,9 +2182,7 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
 
 probe_end:
 	if (ret < 0) {
-		if (last_devlinked_component)
-			snd_soc_remove_device_links(card, last_devlinked_component);
-
+		snd_soc_remove_device_links(card);
 		soc_cleanup_card_resources(card);
 	}
 
Signature · 1 line
2.47.3
maintainer
#1 lore raw
Quoted 1 line · Richard Fitzgerald

ASoC: soc-core: Don't fail if device_link could not be created

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.2

Thanks!

[1/1] ASoC: soc-core: Don't fail if device_link could not be created

      https://git.kernel.org/broonie/sound/c/a7ea04d1ad39

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