Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH] ASoC: core: Move all users to deferrable card binding
@ 2026-04-30 14:07 Cezary Rojewski
  2026-05-11  1:06 ` Mark Brown
  2026-05-11  1:34 ` Kuninori Morimoto
  0 siblings, 2 replies; 3+ messages in thread
From: Cezary Rojewski @ 2026-04-30 14:07 UTC (permalink / raw)
  To: broonie
  Cc: tiwai, perex, amade, kuninori.morimoto.gx, linux-sound,
	Cezary Rojewski

Commit a3375522bb5e2 ("ASoC: core: Complete support for card rebinding")
completed the feature and at the same time divided ASoC users into two
groups:

1) cards that fail to enumerate the moment one of the components is
   not available
2) cards that succeed to enumerate even if some of their components
   become available late

Given the component-based nature of ASoC, approach 2) is preferred and
can be used by all ASoC users.  By dropping 1) the card binding code can
also be simplified.

Flatten code that is currently conditional based on ->devres_dev and
convert snd_soc_rebind_card() to call_soc_bind_card().  The latter is a
selector between managed and unmanaged card-binding behaviour to keep
non-devm users happy.

With rebinding being the default, devm_snd_soc_register_card() takes
form of its deferrable friend - all the devm job is already done by
devm_snd_soc_bind_card().

Suggested-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
---

This is a direct continuation of subject [1] begun by Kuninori with goal
of simplifying the code related to card rebinding.

[1]: https://lore.kernel.org/linux-sound/87eck7k868.wl-kuninori.morimoto.gx@renesas.com/

 include/sound/soc.h    |  2 +-
 sound/soc/soc-core.c   | 44 ++++++++++++++----------------------------
 sound/soc/soc-devres.c | 28 +--------------------------
 3 files changed, 17 insertions(+), 57 deletions(-)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index a30f95ff7d86..f0935523c8df 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -425,7 +425,7 @@ struct snd_soc_jack_pin;
 int snd_soc_register_card(struct snd_soc_card *card);
 void snd_soc_unregister_card(struct snd_soc_card *card);
 int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card);
-int devm_snd_soc_register_deferrable_card(struct device *dev, struct snd_soc_card *card);
+#define devm_snd_soc_register_deferrable_card(d, c) devm_snd_soc_register_card(d, c)
 #ifdef CONFIG_PM_SLEEP
 int snd_soc_suspend(struct device *dev);
 int snd_soc_resume(struct device *dev);
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index e70bf22db5c9..ec141b810b50 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2165,6 +2165,7 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
 	snd_soc_fill_dummy_dai(card);
 
 	snd_soc_dapm_init(dapm, card, NULL);
+	list_del_init(&card->list);
 
 	/* check whether any platform is ignore machine FE and using topology */
 	soc_check_tplg_fes(card);
@@ -2308,6 +2309,10 @@ static int snd_soc_bind_card(struct snd_soc_card *card)
 probe_end:
 	if (ret < 0)
 		soc_cleanup_card_resources(card);
+	if (ret == -EPROBE_DEFER) {
+		list_add(&card->list, &unbind_card_list);
+		ret = 0;
+	}
 	snd_soc_card_mutex_unlock(card);
 
 	return ret;
@@ -2323,12 +2328,15 @@ static int devm_snd_soc_bind_card(struct device *dev, struct snd_soc_card *card)
 	struct snd_soc_card **ptr;
 	int ret;
 
+	/* The procedure may be called many times during the lifetime of the card. */
+	devres_destroy(dev, devm_card_bind_release, NULL, NULL);
+
 	ptr = devres_alloc(devm_card_bind_release, sizeof(*ptr), GFP_KERNEL);
 	if (!ptr)
 		return -ENOMEM;
 
 	ret = snd_soc_bind_card(card);
-	if (ret == 0 || ret == -EPROBE_DEFER) {
+	if (ret == 0) {
 		*ptr = card;
 		devres_add(dev, ptr);
 	} else {
@@ -2338,21 +2346,11 @@ static int devm_snd_soc_bind_card(struct device *dev, struct snd_soc_card *card)
 	return ret;
 }
 
-static int snd_soc_rebind_card(struct snd_soc_card *card)
+static int call_soc_bind_card(struct snd_soc_card *card)
 {
-	int ret;
-
-	if (card->devres_dev) {
-		devres_destroy(card->devres_dev, devm_card_bind_release, NULL, NULL);
-		ret = devm_snd_soc_bind_card(card->devres_dev, card);
-	} else {
-		ret = snd_soc_bind_card(card);
-	}
-
-	if (ret != -EPROBE_DEFER)
-		list_del_init(&card->list);
-
-	return ret;
+	if (card->devres_dev)
+		return devm_snd_soc_bind_card(card->devres_dev, card);
+	return snd_soc_bind_card(card);
 }
 
 /* probes a new socdev */
@@ -2550,8 +2548,6 @@ EXPORT_SYMBOL_GPL(snd_soc_add_dai_controls);
  */
 int snd_soc_register_card(struct snd_soc_card *card)
 {
-	int ret;
-
 	if (!card->name || !card->dev)
 		return -EINVAL;
 
@@ -2578,17 +2574,7 @@ int snd_soc_register_card(struct snd_soc_card *card)
 
 	guard(mutex)(&client_mutex);
 
-	if (card->devres_dev) {
-		ret = devm_snd_soc_bind_card(card->devres_dev, card);
-		if (ret == -EPROBE_DEFER) {
-			list_add(&card->list, &unbind_card_list);
-			ret = 0;
-		}
-	} else {
-		ret = snd_soc_bind_card(card);
-	}
-
-	return ret;
+	return call_soc_bind_card(card);
 }
 EXPORT_SYMBOL_GPL(snd_soc_register_card);
 
@@ -2909,7 +2895,7 @@ int snd_soc_add_component(struct snd_soc_component *component,
 	list_add(&component->list, &component_list);
 
 	list_for_each_entry_safe(card, c, &unbind_card_list, list)
-		snd_soc_rebind_card(card);
+		call_soc_bind_card(card);
 
 err_cleanup:
 	if (ret < 0)
diff --git a/sound/soc/soc-devres.c b/sound/soc/soc-devres.c
index d33f83ec24f2..718165ba84ac 100644
--- a/sound/soc/soc-devres.c
+++ b/sound/soc/soc-devres.c
@@ -49,11 +49,6 @@ int devm_snd_soc_register_component(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(devm_snd_soc_register_component);
 
-static void devm_card_release(struct device *dev, void *res)
-{
-	snd_soc_unregister_card(*(struct snd_soc_card **)res);
-}
-
 /**
  * devm_snd_soc_register_card - resource managed card registration
  * @dev: Device used to manage card
@@ -63,32 +58,11 @@ static void devm_card_release(struct device *dev, void *res)
  * unregistered.
  */
 int devm_snd_soc_register_card(struct device *dev, struct snd_soc_card *card)
-{
-	struct snd_soc_card **ptr;
-	int ret;
-
-	ptr = devres_alloc(devm_card_release, sizeof(*ptr), GFP_KERNEL);
-	if (!ptr)
-		return -ENOMEM;
-
-	ret = snd_soc_register_card(card);
-	if (ret == 0) {
-		*ptr = card;
-		devres_add(dev, ptr);
-	} else {
-		devres_free(ptr);
-	}
-
-	return ret;
-}
-EXPORT_SYMBOL_GPL(devm_snd_soc_register_card);
-
-int devm_snd_soc_register_deferrable_card(struct device *dev, struct snd_soc_card *card)
 {
 	card->devres_dev = dev;
 	return snd_soc_register_card(card);
 }
-EXPORT_SYMBOL_GPL(devm_snd_soc_register_deferrable_card);
+EXPORT_SYMBOL_GPL(devm_snd_soc_register_card);
 
 #ifdef CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM
 
-- 
2.34.1


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

* Re: [PATCH] ASoC: core: Move all users to deferrable card binding
  2026-04-30 14:07 [PATCH] ASoC: core: Move all users to deferrable card binding Cezary Rojewski
@ 2026-05-11  1:06 ` Mark Brown
  2026-05-11  1:34 ` Kuninori Morimoto
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2026-05-11  1:06 UTC (permalink / raw)
  To: Cezary Rojewski; +Cc: tiwai, perex, amade, kuninori.morimoto.gx, linux-sound

On Thu, 30 Apr 2026 16:07:52 +0200, Cezary Rojewski wrote:
> ASoC: core: Move all users to deferrable card binding

Applied to

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

Thanks!

[1/1] ASoC: core: Move all users to deferrable card binding
      https://git.kernel.org/broonie/sound/c/42d99857d6f0

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

* Re: [PATCH] ASoC: core: Move all users to deferrable card binding
  2026-04-30 14:07 [PATCH] ASoC: core: Move all users to deferrable card binding Cezary Rojewski
  2026-05-11  1:06 ` Mark Brown
@ 2026-05-11  1:34 ` Kuninori Morimoto
  1 sibling, 0 replies; 3+ messages in thread
From: Kuninori Morimoto @ 2026-05-11  1:34 UTC (permalink / raw)
  To: Cezary Rojewski; +Cc: broonie, tiwai, perex, amade, linux-sound


Hi Cezary

Thank you for the patch.
And sorry for my late response, it was long holiday in Japan.

> Commit a3375522bb5e2 ("ASoC: core: Complete support for card rebinding")
> completed the feature and at the same time divided ASoC users into two
> groups:
> 
> 1) cards that fail to enumerate the moment one of the components is
>    not available
> 2) cards that succeed to enumerate even if some of their components
>    become available late
> 
> Given the component-based nature of ASoC, approach 2) is preferred and
> can be used by all ASoC users.  By dropping 1) the card binding code can
> also be simplified.
> 
> Flatten code that is currently conditional based on ->devres_dev and
> convert snd_soc_rebind_card() to call_soc_bind_card().  The latter is a
> selector between managed and unmanaged card-binding behaviour to keep
> non-devm users happy.
> 
> With rebinding being the default, devm_snd_soc_register_card() takes
> form of its deferrable friend - all the devm job is already done by
> devm_snd_soc_bind_card().
> 
> Suggested-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
> ---

It looks more simple, thank you !

2 questions.

Q1. this means, devm_ register user can use auto rebind, normal user can't,
    but is this correct ?
Q2. If so, list_xxx() can be done in devm_snd_soc_bind_card(), instead of
    normal snd_soc_bind_card(), but what do you think ?

Thank you for your help !!

Best regards
---
Kuninori Morimoto

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

end of thread, other threads:[~2026-05-11 12:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 14:07 [PATCH] ASoC: core: Move all users to deferrable card binding Cezary Rojewski
2026-05-11  1:06 ` Mark Brown
2026-05-11  1:34 ` Kuninori Morimoto

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox