ASoC: soc-core.c: Prefer to return dai->driver->name in snd_soc_dai_name_get()
authorChancel Liu <chancel.liu@nxp.com>
Mon, 4 Mar 2024 07:21:28 +0000 (16:21 +0900)
committerMark Brown <broonie@kernel.org>
Mon, 4 Mar 2024 20:27:36 +0000 (20:27 +0000)
ASoC machine driver can use snd_soc_{of_}get_dlc() (A) to get DAI name
for dlc (snd_soc_dai_link_component). In this function call
dlc->dai_name is parsed via snd_soc_dai_name_get() (B).

(A) int snd_soc_get_dlc(...)
{
...
(B) dlc->dai_name = snd_soc_dai_name_get(dai);
...
}

(B) has a priority to return dai->name as dlc->dai_name. In most cases
card can probe successfully. However it has an issue that ASoC tries to
rebind card. Here is a simplified flow for example:

 | a) Card probes successfully at first
 | b) One of the component bound to this card is removed for some
 |    reason the component->dev is released
 | c) That component is re-registered
 v d) ASoC calls snd_soc_try_rebind_card()

a) points dlc->dai_name to dai->name. b) releases all resource of the
old DAI. c) creates new DAI structure. In result d) can not use
dlc->dai_name to add new created DAI.

So it's reasonable that prefer to return dai->driver->name in
snd_soc_dai_name_get() because dai->driver is a pre-defined global
variable. Also update snd_soc_is_matching_dai() for alignment.

Signed-off-by: Chancel Liu <chancel.liu@nxp.com>
Link: https://msgid.link/r/20240304072128.2845432-1-chancel.liu@nxp.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/soc-core.c

index 507cd3015ff4cd35f6c3ade10d23224c1053e359..1e94edba12eb85706d0f1f0acf7c75ad3a8249eb 100644 (file)
@@ -283,13 +283,13 @@ static int snd_soc_is_matching_dai(const struct snd_soc_dai_link_component *dlc,
 
        /* see snd_soc_dai_name_get() */
 
-       if (strcmp(dlc->dai_name, dai->name) == 0)
-               return 1;
-
        if (dai->driver->name &&
            strcmp(dlc->dai_name, dai->driver->name) == 0)
                return 1;
 
+       if (strcmp(dlc->dai_name, dai->name) == 0)
+               return 1;
+
        if (dai->component->name &&
            strcmp(dlc->dai_name, dai->component->name) == 0)
                return 1;
@@ -300,12 +300,12 @@ static int snd_soc_is_matching_dai(const struct snd_soc_dai_link_component *dlc,
 const char *snd_soc_dai_name_get(struct snd_soc_dai *dai)
 {
        /* see snd_soc_is_matching_dai() */
-       if (dai->name)
-               return dai->name;
-
        if (dai->driver->name)
                return dai->driver->name;
 
+       if (dai->name)
+               return dai->name;
+
        if (dai->component->name)
                return dai->component->name;