From: Cezary Rojewski <cezary.rojewski@intel.com>
To: broonie@kernel.org
Cc: tiwai@suse.com, perex@perex.cz, amade@asmblr.net,
kuninori.morimoto.gx@renesas.com, linux-sound@vger.kernel.org,
Cezary Rojewski <cezary.rojewski@intel.com>
Subject: [PATCH] ASoC: core: Move all users to deferrable card binding
Date: Thu, 30 Apr 2026 16:07:52 +0200 [thread overview]
Message-ID: <20260430140752.766130-1-cezary.rojewski@intel.com> (raw)
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
next reply other threads:[~2026-04-30 14:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 14:07 Cezary Rojewski [this message]
2026-05-11 1:06 ` [PATCH] ASoC: core: Move all users to deferrable card binding Mark Brown
2026-05-11 1:34 ` Kuninori Morimoto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260430140752.766130-1-cezary.rojewski@intel.com \
--to=cezary.rojewski@intel.com \
--cc=amade@asmblr.net \
--cc=broonie@kernel.org \
--cc=kuninori.morimoto.gx@renesas.com \
--cc=linux-sound@vger.kernel.org \
--cc=perex@perex.cz \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox