Commit 70b77321 authored by Takashi Iwai's avatar Takashi Iwai Committed by Mark Brown

ASoC: qcom: Fix of-node refcount unbalance in qcom_snd_parse_of()

Although qcom_snd_parse_of() tries to manage the of-node refcount,
there are still a few places that lead to the unblanced refcount in
the error code path.  Namely,

- for_each_child_of_node() needs to unreference the iterator node if
  aborting the loop in the middle,
- cpu, codec and platform node objects have to be unreferenced at each
  iteration,
- platform and codec node objects have to be referred before jumping
  to the error handling code that unreference them unconditionally.

This patch tries to address these by moving the assignment of platform
and codec node objects to the beginning of the loop and adding the
of_node_put() calls adequately.

Fixes: c25e295c ("ASoC: qcom: Add support to parse common audio device nodes")
Cc: Patrick Lai <plai@codeaurora.org>
Cc: Banajit Goswami <bgoswami@codeaurora.org>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 8d166720
...@@ -42,6 +42,9 @@ int qcom_snd_parse_of(struct snd_soc_card *card) ...@@ -42,6 +42,9 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
link = card->dai_link; link = card->dai_link;
for_each_child_of_node(dev->of_node, np) { for_each_child_of_node(dev->of_node, np) {
cpu = of_get_child_by_name(np, "cpu"); cpu = of_get_child_by_name(np, "cpu");
platform = of_get_child_by_name(np, "platform");
codec = of_get_child_by_name(np, "codec");
if (!cpu) { if (!cpu) {
dev_err(dev, "Can't find cpu DT node\n"); dev_err(dev, "Can't find cpu DT node\n");
ret = -EINVAL; ret = -EINVAL;
...@@ -63,8 +66,6 @@ int qcom_snd_parse_of(struct snd_soc_card *card) ...@@ -63,8 +66,6 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
goto err; goto err;
} }
platform = of_get_child_by_name(np, "platform");
codec = of_get_child_by_name(np, "codec");
if (codec && platform) { if (codec && platform) {
link->platform_of_node = of_parse_phandle(platform, link->platform_of_node = of_parse_phandle(platform,
"sound-dai", "sound-dai",
...@@ -100,10 +101,15 @@ int qcom_snd_parse_of(struct snd_soc_card *card) ...@@ -100,10 +101,15 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
link->dpcm_capture = 1; link->dpcm_capture = 1;
link->stream_name = link->name; link->stream_name = link->name;
link++; link++;
of_node_put(cpu);
of_node_put(codec);
of_node_put(platform);
} }
return 0; return 0;
err: err:
of_node_put(np);
of_node_put(cpu); of_node_put(cpu);
of_node_put(codec); of_node_put(codec);
of_node_put(platform); of_node_put(platform);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment