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

Configure Feed

Select the types of activity you want to include in your feed.

ASoC: generic: keep fallback dai_name stable across rebind

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.

Suggested-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com>
Link: https://patch.msgid.link/20260327-asoc-generic-fallback-dai-name-rebind-v3-1-c206e44f40c8@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Cássio Gabriel and committed by
Mark Brown
aa173b70 18cc8cc3

+45 -55
+24 -30
sound/soc/generic/simple-card-utils.c
··· 1128 1128 struct device *dev = simple_priv_to_dev(priv); 1129 1129 struct device_node *node; 1130 1130 struct of_phandle_args args = {}; 1131 + struct snd_soc_dai_link_component resolved_dlc = {}; 1131 1132 struct snd_soc_dai *dai; 1133 + const char *fallback_dai_name; 1132 1134 int ret; 1133 1135 1134 1136 if (!ep) ··· 1154 1152 dlc->of_node = node; 1155 1153 dlc->dai_name = dai_name; 1156 1154 dlc->dai_args = dai_args; 1155 + } else { 1156 + /* Get dai->name */ 1157 + args.np = node; 1158 + args.args[0] = graph_get_dai_id(ep); 1159 + args.args_count = (of_graph_get_endpoint_count(node) > 1); 1157 1160 1158 - goto parse_dai_end; 1161 + ret = snd_soc_get_dlc(&args, &resolved_dlc); 1162 + if (ret < 0) 1163 + goto err; 1164 + 1165 + /* Keep fallback dai_name valid across component rebind */ 1166 + fallback_dai_name = resolved_dlc.dai_name; 1167 + if (fallback_dai_name) { 1168 + fallback_dai_name = devm_kstrdup_const(dev, fallback_dai_name, 1169 + GFP_KERNEL); 1170 + ret = -ENOMEM; 1171 + if (!fallback_dai_name) 1172 + goto err; 1173 + } 1174 + 1175 + dlc->of_node = resolved_dlc.of_node; 1176 + dlc->dai_name = fallback_dai_name; 1177 + dlc->dai_args = resolved_dlc.dai_args; 1159 1178 } 1160 1179 1161 - /* Get dai->name */ 1162 - args.np = node; 1163 - args.args[0] = graph_get_dai_id(ep); 1164 - args.args_count = (of_graph_get_endpoint_count(node) > 1); 1165 - 1166 - /* 1167 - * FIXME 1168 - * 1169 - * Here, dlc->dai_name is pointer to CPU/Codec DAI name. 1170 - * If user unbinded CPU or Codec driver, but not for Sound Card, 1171 - * dlc->dai_name is keeping unbinded CPU or Codec 1172 - * driver's pointer. 1173 - * 1174 - * If user re-bind CPU or Codec driver again, ALSA SoC will try 1175 - * to rebind Card via snd_soc_try_rebind_card(), but because of 1176 - * above reason, it might can't bind Sound Card. 1177 - * Because Sound Card is pointing to released dai_name pointer. 1178 - * 1179 - * To avoid this rebind Card issue, 1180 - * 1) It needs to alloc memory to keep dai_name eventhough 1181 - * CPU or Codec driver was unbinded, or 1182 - * 2) user need to rebind Sound Card everytime 1183 - * if he unbinded CPU or Codec. 1184 - */ 1185 - ret = snd_soc_get_dlc(&args, dlc); 1186 - if (ret < 0) 1187 - goto err; 1188 - 1189 - parse_dai_end: 1190 1180 if (is_single_link) 1191 1181 *is_single_link = of_graph_get_endpoint_count(node) == 1; 1192 1182 ret = 0;
+21 -25
sound/soc/generic/simple-card.c
··· 69 69 { 70 70 struct device *dev = simple_priv_to_dev(priv); 71 71 struct of_phandle_args args; 72 + struct snd_soc_dai_link_component resolved_dlc = {}; 72 73 struct snd_soc_dai *dai; 74 + const char *fallback_dai_name; 73 75 int ret; 74 76 75 77 if (!node) ··· 96 94 dlc->dai_args = snd_soc_copy_dai_args(dev, &args); 97 95 if (!dlc->dai_args) 98 96 goto end; 97 + } else { 98 + ret = snd_soc_get_dlc(&args, &resolved_dlc); 99 + if (ret < 0) 100 + goto end; 99 101 100 - goto parse_dai_end; 102 + /* Keep fallback dai_name valid across component rebind */ 103 + fallback_dai_name = resolved_dlc.dai_name; 104 + if (fallback_dai_name) { 105 + fallback_dai_name = devm_kstrdup_const(dev, fallback_dai_name, 106 + GFP_KERNEL); 107 + ret = -ENOMEM; 108 + if (!fallback_dai_name) { 109 + of_node_put(resolved_dlc.of_node); 110 + goto end; 111 + } 112 + } 113 + 114 + dlc->of_node = resolved_dlc.of_node; 115 + dlc->dai_name = fallback_dai_name; 116 + dlc->dai_args = resolved_dlc.dai_args; 101 117 } 102 118 103 - /* 104 - * FIXME 105 - * 106 - * Here, dlc->dai_name is pointer to CPU/Codec DAI name. 107 - * If user unbinded CPU or Codec driver, but not for Sound Card, 108 - * dlc->dai_name is keeping unbinded CPU or Codec 109 - * driver's pointer. 110 - * 111 - * If user re-bind CPU or Codec driver again, ALSA SoC will try 112 - * to rebind Card via snd_soc_try_rebind_card(), but because of 113 - * above reason, it might can't bind Sound Card. 114 - * Because Sound Card is pointing to released dai_name pointer. 115 - * 116 - * To avoid this rebind Card issue, 117 - * 1) It needs to alloc memory to keep dai_name eventhough 118 - * CPU or Codec driver was unbinded, or 119 - * 2) user need to rebind Sound Card everytime 120 - * if he unbinded CPU or Codec. 121 - */ 122 - ret = snd_soc_get_dlc(&args, dlc); 123 - if (ret < 0) 124 - goto end; 125 - 126 - parse_dai_end: 127 119 if (is_single_link) 128 120 *is_single_link = !args.args_count; 129 121 ret = 0;