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: simple-card-utils: fixup dlc->xxx handling for error case

Current graph_util_parse_dai() has 2 issue for dlc->xxx handling.

1) dlc->xxx might be filled if snd_soc_get_dai_via_args() (A) works.
In such case it will fill dlc->xxx first (B), and detect error
after that (C). We need to fill dlc->xxx in success case only.

(A) dai = snd_soc_get_dai_via_args(&args);
if (dai) {
ret = -ENOMEM;
^ dlc->of_node = ...
(B) dlc->dai_name = ...
v dlc->dai_args = ...
(C) if (!dlc->dai_args)
goto end;
...
}

2) graph_util_parse_dai() itself has 2 patterns (X)(Y) to fill dlc->xxx.
Both case, we need to call of_node_put(node) (Z) in error case, but we
are calling it only in (Y) case.

int graph_util_parse_dai(...)
{
...
dai = snd_soc_get_dai_via_args(&args);
if (dai) {
...
^ dlc->of_node = ...
(X) dlc->dai_name = ...
v dlc->dai_args = ...
...
}
...
(Y) ret = snd_soc_get_dlc(&args, dlc);
if (ret < 0) {
(Z) of_node_put(node);
...
}
...
}

This patch fixup both case. Make it easy to understand, update
lavel "end" to "err", too.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Link: https://patch.msgid.link/87fribr2ns.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Kuninori Morimoto and committed by
Mark Brown
2b4ce994 2c6b6a3e

+14 -9
+14 -9
sound/soc/generic/simple-card-utils.c
··· 1119 1119 args.np = ep; 1120 1120 dai = snd_soc_get_dai_via_args(&args); 1121 1121 if (dai) { 1122 + const char *dai_name = snd_soc_dai_name_get(dai); 1123 + const struct of_phandle_args *dai_args = snd_soc_copy_dai_args(dev, &args); 1124 + 1122 1125 ret = -ENOMEM; 1126 + if (!dai_args) 1127 + goto err; 1128 + 1123 1129 dlc->of_node = node; 1124 - dlc->dai_name = snd_soc_dai_name_get(dai); 1125 - dlc->dai_args = snd_soc_copy_dai_args(dev, &args); 1126 - if (!dlc->dai_args) 1127 - goto end; 1130 + dlc->dai_name = dai_name; 1131 + dlc->dai_args = dai_args; 1128 1132 1129 1133 goto parse_dai_end; 1130 1134 } ··· 1158 1154 * if he unbinded CPU or Codec. 1159 1155 */ 1160 1156 ret = snd_soc_get_dlc(&args, dlc); 1161 - if (ret < 0) { 1162 - of_node_put(node); 1163 - goto end; 1164 - } 1157 + if (ret < 0) 1158 + goto err; 1165 1159 1166 1160 parse_dai_end: 1167 1161 if (is_single_link) 1168 1162 *is_single_link = of_graph_get_endpoint_count(node) == 1; 1169 1163 ret = 0; 1170 - end: 1164 + err: 1165 + if (ret < 0) 1166 + of_node_put(node); 1167 + 1171 1168 return simple_ret(priv, ret); 1172 1169 } 1173 1170 EXPORT_SYMBOL_GPL(graph_util_parse_dai);