sound/soc/generic/simple-card-utils.c | 37 +++++++++++++++------------------ sound/soc/generic/simple-card.c | 39 +++++++++++++++++------------------ 2 files changed, 36 insertions(+), 40 deletions(-)
simple_parse_dai() and graph_util_parse_dai() first try to identify a
DAI via dai_args. When that works the card can rebind without relying on
dlc->dai_name.
The fallback path still calls snd_soc_get_dlc(), which returns a
borrowed dai_name pointer. If the CPU or codec component is unbound
while the sound card stays registered, the generic card keeps that
pointer and the next rebind may compare stale memory while matching the
DAI.
Stage the fallback result in a temporary dai_link_component and move
only a card-owned copy of dai_name into the live link component. Use
devm_kstrdup_const() so static names are reused and dynamic ones remain
valid for the lifetime of the card device.
Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com>
---
sound/soc/generic/simple-card-utils.c | 37 +++++++++++++++------------------
sound/soc/generic/simple-card.c | 39 +++++++++++++++++------------------
2 files changed, 36 insertions(+), 40 deletions(-)
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c
index da6353594d61..5997bb57e661 100644
--- a/sound/soc/generic/simple-card-utils.c
+++ b/sound/soc/generic/simple-card-utils.c
@@ -1128,7 +1128,9 @@ int graph_util_parse_dai(struct simple_util_priv *priv, struct device_node *ep,
struct device *dev = simple_priv_to_dev(priv);
struct device_node *node;
struct of_phandle_args args = {};
+ struct snd_soc_dai_link_component resolved_dlc = {};
struct snd_soc_dai *dai;
+ const char *fallback_dai_name;
int ret;
if (!ep)
@@ -1161,29 +1163,24 @@ int graph_util_parse_dai(struct simple_util_priv *priv, struct device_node *ep,
args.args[0] = graph_get_dai_id(ep);
args.args_count = (of_graph_get_endpoint_count(node) > 1);
- /*
- * FIXME
- *
- * Here, dlc->dai_name is pointer to CPU/Codec DAI name.
- * If user unbinded CPU or Codec driver, but not for Sound Card,
- * dlc->dai_name is keeping unbinded CPU or Codec
- * driver's pointer.
- *
- * If user re-bind CPU or Codec driver again, ALSA SoC will try
- * to rebind Card via snd_soc_try_rebind_card(), but because of
- * above reason, it might can't bind Sound Card.
- * Because Sound Card is pointing to released dai_name pointer.
- *
- * To avoid this rebind Card issue,
- * 1) It needs to alloc memory to keep dai_name eventhough
- * CPU or Codec driver was unbinded, or
- * 2) user need to rebind Sound Card everytime
- * if he unbinded CPU or Codec.
- */
- ret = snd_soc_get_dlc(&args, dlc);
+ ret = snd_soc_get_dlc(&args, &resolved_dlc);
if (ret < 0)
goto err;
+ /* Keep fallback dai_name valid across component rebind */
+ fallback_dai_name = resolved_dlc.dai_name;
+ if (fallback_dai_name) {
+ fallback_dai_name = devm_kstrdup_const(dev, fallback_dai_name,
+ GFP_KERNEL);
+ ret = -ENOMEM;
+ if (!fallback_dai_name)
+ goto err;
+ }
+
+ dlc->of_node = resolved_dlc.of_node;
+ dlc->dai_name = fallback_dai_name;
+ dlc->dai_args = resolved_dlc.dai_args;
+
parse_dai_end:
if (is_single_link)
*is_single_link = of_graph_get_endpoint_count(node) == 1;
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 9937a991846e..7c399a9713ca 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -69,7 +69,9 @@ static int simple_parse_dai(struct simple_util_priv *priv,
{
struct device *dev = simple_priv_to_dev(priv);
struct of_phandle_args args;
+ struct snd_soc_dai_link_component resolved_dlc = {};
struct snd_soc_dai *dai;
+ const char *fallback_dai_name;
int ret;
if (!node)
@@ -98,29 +100,26 @@ static int simple_parse_dai(struct simple_util_priv *priv,
goto parse_dai_end;
}
- /*
- * FIXME
- *
- * Here, dlc->dai_name is pointer to CPU/Codec DAI name.
- * If user unbinded CPU or Codec driver, but not for Sound Card,
- * dlc->dai_name is keeping unbinded CPU or Codec
- * driver's pointer.
- *
- * If user re-bind CPU or Codec driver again, ALSA SoC will try
- * to rebind Card via snd_soc_try_rebind_card(), but because of
- * above reason, it might can't bind Sound Card.
- * Because Sound Card is pointing to released dai_name pointer.
- *
- * To avoid this rebind Card issue,
- * 1) It needs to alloc memory to keep dai_name eventhough
- * CPU or Codec driver was unbinded, or
- * 2) user need to rebind Sound Card everytime
- * if he unbinded CPU or Codec.
- */
- ret = snd_soc_get_dlc(&args, dlc);
+ ret = snd_soc_get_dlc(&args, &resolved_dlc);
if (ret < 0)
goto end;
+ /* Keep fallback dai_name valid across component rebind */
+ fallback_dai_name = resolved_dlc.dai_name;
+ if (fallback_dai_name) {
+ fallback_dai_name = devm_kstrdup_const(dev, fallback_dai_name,
+ GFP_KERNEL);
+ ret = -ENOMEM;
+ if (!fallback_dai_name) {
+ of_node_put(resolved_dlc.of_node);
+ goto end;
+ }
+ }
+
+ dlc->of_node = resolved_dlc.of_node;
+ dlc->dai_name = fallback_dai_name;
+ dlc->dai_args = resolved_dlc.dai_args;
+
parse_dai_end:
if (is_single_link)
*is_single_link = !args.args_count;
---
base-commit: d084fd53a2fd5748d4317635b1c1a7dba7edf583
change-id: 20260326-asoc-generic-fallback-dai-name-rebind-6381a1c807fd
Best regards,
--
Cássio Gabriel <cassiogabrielcontato@gmail.com>
Hi Cássio
Thank you for your patch
> simple_parse_dai() and graph_util_parse_dai() first try to identify a
> DAI via dai_args. When that works the card can rebind without relying on
> dlc->dai_name.
>
> The fallback path still calls snd_soc_get_dlc(), which returns a
> borrowed dai_name pointer. If the CPU or codec component is unbound
> while the sound card stays registered, the generic card keeps that
> pointer and the next rebind may compare stale memory while matching the
> DAI.
>
> Stage the fallback result in a temporary dai_link_component and move
> only a card-owned copy of dai_name into the live link component. Use
> devm_kstrdup_const() so static names are reused and dynamic ones remain
> valid for the lifetime of the card device.
>
> Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com>
> ---
It looks good to me.
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
1 concern is that this function is using goto, ad your code is fixing
(A) part.
int graph_util_parse_dai(...)
{
...
dai = snd_soc_get_dai_via_args(...);
if (dai) {
...
=> goto parse_dai_end;
}
(A) ...
parse_dai_end:
...
}
I think it is good timing to use if-else here ?
int graph_util_parse_dai(...)
{
...
dai = snd_soc_get_dai_via_args(...);
if (dai) {
...
+ } else {
+ (A) ...
+ }
...
}
Thank you for your help !!
Best regards
---
Kuninori Morimoto
Hi, Kuninori
On 3/26/26 22:11, Kuninori Morimoto wrote:
>
> Hi Cássio
>
> Thank you for your patch
>
>> simple_parse_dai() and graph_util_parse_dai() first try to identify a
>> DAI via dai_args. When that works the card can rebind without relying on
>> dlc->dai_name.
>>
>> The fallback path still calls snd_soc_get_dlc(), which returns a
>> borrowed dai_name pointer. If the CPU or codec component is unbound
>> while the sound card stays registered, the generic card keeps that
>> pointer and the next rebind may compare stale memory while matching the
>> DAI.
>>
>> Stage the fallback result in a temporary dai_link_component and move
>> only a card-owned copy of dai_name into the live link component. Use
>> devm_kstrdup_const() so static names are reused and dynamic ones remain
>> valid for the lifetime of the card device.
>>
>> Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com>
>> ---
>
> It looks good to me.
>
> Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
>
> 1 concern is that this function is using goto, ad your code is fixing
> (A) part.
>
> int graph_util_parse_dai(...)
> {
> ...
> dai = snd_soc_get_dai_via_args(...);
> if (dai) {
> ...
> => goto parse_dai_end;
> }
>
> (A) ...
>
> parse_dai_end:
> ...
> }
>
>
> I think it is good timing to use if-else here ?
>
> int graph_util_parse_dai(...)
> {
> ...
> dai = snd_soc_get_dai_via_args(...);
> if (dai) {
> ...
> + } else {
> + (A) ...
> + }
> ...
> }
>
>
That makes sense, and it’s clearer.
I’m going to send the v2 patch with the changes.
>
> Thank you for your help !!
>
> Best regards
> ---
> Kuninori Morimoto
--
Thanks,
Cássio
© 2016 - 2026 Red Hat, Inc.