From: Takashi Iwai <tiwai@suse.de>
To: Mark Brown <broonie@kernel.org>
Cc: alsa-devel@alsa-project.org,
Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Subject: [PATCH 3/6] ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser
Date: Tue, 19 Feb 2019 16:46:49 +0100 [thread overview]
Message-ID: <20190219154652.13644-4-tiwai@suse.de> (raw)
In-Reply-To: <20190219154652.13644-1-tiwai@suse.de>
The function simple_for_each_link() has a few missing places that
forgot unrefereing of-nodes after the use. The main do-while loop
may abort when loop=0, and this leaves the node object still
referenced. A similar leak is found in the error handling of NULL
codec that aborts the loop as well. Last but not least, the inner
for_each_child_of_node() loop may abort in the middle, and this leaks
the refcount of the iterator node.
This patch addresses these missing refcount issues.
Cc: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---
Only compile-tested. Please review carefully. Thanks!
sound/soc/generic/simple-card.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 3e677dd1137e..30ae0a5281b3 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -442,6 +442,7 @@ static int simple_for_each_link(struct simple_priv *priv,
struct device_node *top = dev->of_node;
struct device_node *node;
bool is_top = 0;
+ int ret = 0;
/* Check if it has dai-link */
node = of_get_child_by_name(top, PREFIX "dai-link");
@@ -456,13 +457,14 @@ static int simple_for_each_link(struct simple_priv *priv,
struct device_node *codec;
struct device_node *np;
int num = of_get_child_count(node);
- int ret;
/* get codec */
codec = of_get_child_by_name(node, is_top ?
PREFIX "codec" : "codec");
- if (!codec)
- return -ENODEV;
+ if (!codec) {
+ ret = -ENODEV;
+ goto error;
+ }
of_node_put(codec);
@@ -485,14 +487,18 @@ static int simple_for_each_link(struct simple_priv *priv,
else
ret = func_noml(priv, np, codec, li, is_top);
- if (ret < 0)
- return ret;
+ if (ret < 0) {
+ of_node_put(np);
+ goto error;
+ }
}
node = of_get_next_child(top, node);
} while (!is_top && node);
- return 0;
+ error:
+ of_node_put(node);
+ return ret;
}
static int simple_parse_aux_devs(struct device_node *node,
--
2.16.4
next prev parent reply other threads:[~2019-02-19 15:46 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-19 15:46 [PATCH 0/6] ASoC: Fix of-node refcount unbalance Takashi Iwai
2019-02-19 15:46 ` [PATCH 1/6] ASoC: fsl: Fix of-node refcount unbalance in fsl_ssi_probe_from_dt() Takashi Iwai
2019-02-20 5:29 ` Nicolin Chen
2019-02-20 12:13 ` Applied "ASoC: fsl: Fix of-node refcount unbalance in fsl_ssi_probe_from_dt()" to the asoc tree Mark Brown
2019-02-19 15:46 ` [PATCH 2/6] ASoC: simple-card: Fix missing of_node_put() at simple_dai_link_of() Takashi Iwai
2019-02-20 12:13 ` Applied "ASoC: simple-card: Fix missing of_node_put() at simple_dai_link_of()" to the asoc tree Mark Brown
2019-02-19 15:46 ` Takashi Iwai [this message]
2019-02-20 12:13 ` Applied "ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser" " Mark Brown
2019-02-19 15:46 ` [PATCH 4/6] ASoC: qcom: Fix of-node refcount unbalance in apq8016_sbc_parse_of() Takashi Iwai
2019-02-20 17:52 ` Applied "ASoC: qcom: Fix of-node refcount unbalance in apq8016_sbc_parse_of()" to the asoc tree Mark Brown
2019-02-19 15:46 ` [PATCH 5/6] ASoC: qcom: Fix of-node refcount unbalance in qcom_snd_parse_of() Takashi Iwai
2019-02-20 17:52 ` Applied "ASoC: qcom: Fix of-node refcount unbalance in qcom_snd_parse_of()" to the asoc tree Mark Brown
2019-02-19 15:46 ` [PATCH 6/6] ASoC: samsung: Fix of-node refcount unbalance in odroid_audio_probe() Takashi Iwai
2019-02-19 16:36 ` Sylwester Nawrocki
2019-02-20 10:40 ` Takashi Iwai
2019-02-20 11:06 ` Sylwester Nawrocki
2019-02-20 0:27 ` [PATCH 0/6] ASoC: Fix of-node refcount unbalance Kuninori Morimoto
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190219154652.13644-4-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=kuninori.morimoto.gx@renesas.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox