Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: soc-core.c: Prefer to return dai->driver->name in snd_soc_dai_name_get()

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>

authored by

Chancel Liu and committed by
Mark Brown
755bb9a4 17786231

+6 -6
+6 -6
sound/soc/soc-core.c
··· 283 283 284 284 /* see snd_soc_dai_name_get() */ 285 285 286 - if (strcmp(dlc->dai_name, dai->name) == 0) 287 - return 1; 288 - 289 286 if (dai->driver->name && 290 287 strcmp(dlc->dai_name, dai->driver->name) == 0) 288 + return 1; 289 + 290 + if (strcmp(dlc->dai_name, dai->name) == 0) 291 291 return 1; 292 292 293 293 if (dai->component->name && ··· 300 300 const char *snd_soc_dai_name_get(struct snd_soc_dai *dai) 301 301 { 302 302 /* see snd_soc_is_matching_dai() */ 303 - if (dai->name) 304 - return dai->name; 305 - 306 303 if (dai->driver->name) 307 304 return dai->driver->name; 305 + 306 + if (dai->name) 307 + return dai->name; 308 308 309 309 if (dai->component->name) 310 310 return dai->component->name;