All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] ASoC: Fix of-node refcount unbalance
@ 2019-02-19 15:46 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
                   ` (6 more replies)
  0 siblings, 7 replies; 17+ messages in thread
From: Takashi Iwai @ 2019-02-19 15:46 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel

Hi,

this is a patchset covering the OF-node refcount problem on a few ASoC
drivers.


thanks,

Takashi

===

Takashi Iwai (6):
  ASoC: fsl: Fix of-node refcount unbalance in fsl_ssi_probe_from_dt()
  ASoC: simple-card: Fix missing of_node_put() at simple_dai_link_of()
  ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser
  ASoC: qcom: Fix of-node refcount unbalance in apq8016_sbc_parse_of()
  ASoC: qcom: Fix of-node refcount unbalance in qcom_snd_parse_of()
  ASoC: samsung: Fix of-node refcount unbalance in odroid_audio_probe()

 sound/soc/fsl/fsl_ssi.c         |  6 ++++--
 sound/soc/generic/simple-card.c | 19 +++++++++++++------
 sound/soc/qcom/apq8016_sbc.c    | 21 ++++++++++++++++-----
 sound/soc/qcom/common.c         | 10 ++++++++--
 sound/soc/samsung/odroid.c      |  5 +++--
 5 files changed, 44 insertions(+), 17 deletions(-)

-- 
2.16.4

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [PATCH 1/6] ASoC: fsl: Fix of-node refcount unbalance in fsl_ssi_probe_from_dt()
  2019-02-19 15:46 [PATCH 0/6] ASoC: Fix of-node refcount unbalance Takashi Iwai
@ 2019-02-19 15:46 ` 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
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 17+ messages in thread
From: Takashi Iwai @ 2019-02-19 15:46 UTC (permalink / raw)
  To: Mark Brown; +Cc: Nicolin Chen, alsa-devel, Fabio Estevam, Timur Tabi, Xiubo Li

The node obtained from of_find_node_by_path() has to be unreferenced
after the use, but we forgot it for the root node.

Fixes: f0fba2ad1b6b ("ASoC: multi-component - ASoC Multi-Component Support")
Cc: Timur Tabi <timur@kernel.org>
Cc: Nicolin Chen <nicoleotsuka@gmail.com>
Cc: Xiubo Li <Xiubo.Lee@gmail.com>
Cc: Fabio Estevam <festevam@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---

Only compile-tested.  Please review carefully.  Thanks!

 sound/soc/fsl/fsl_ssi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index 0a648229e643..09b2967befd9 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -1439,8 +1439,10 @@ static int fsl_ssi_probe_from_dt(struct fsl_ssi *ssi)
 	 * different name to register the device.
 	 */
 	if (!ssi->card_name[0] && of_get_property(np, "codec-handle", NULL)) {
-		sprop = of_get_property(of_find_node_by_path("/"),
-					"compatible", NULL);
+		struct device_node *root = of_find_node_by_path("/");
+
+		sprop = of_get_property(root, "compatible", NULL);
+		of_node_put(root);
 		/* Strip "fsl," in the compatible name if applicable */
 		p = strrchr(sprop, ',');
 		if (p)
-- 
2.16.4

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 2/6] ASoC: simple-card: Fix missing of_node_put() at simple_dai_link_of()
  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-19 15:46 ` 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 ` [PATCH 3/6] ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser Takashi Iwai
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Takashi Iwai @ 2019-02-19 15:46 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Kuninori Morimoto

We forgot to unreference the platform node object obtained from
of_get_child_by_name().  This leads to the unbalance of node
refcount.

Fixes: e0ae225b7e96 ("ASoC: simple-card: support platform in dts parse")
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 | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index 08df261024cf..3e677dd1137e 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -421,6 +421,7 @@ static int simple_dai_link_of(struct simple_priv *priv,
 	asoc_simple_card_canonicalize_platform(dai_link);
 
 dai_link_of_err:
+	of_node_put(plat);
 	of_node_put(node);
 
 	return ret;
-- 
2.16.4

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 3/6] ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser
  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-19 15:46 ` [PATCH 2/6] ASoC: simple-card: Fix missing of_node_put() at simple_dai_link_of() Takashi Iwai
@ 2019-02-19 15:46 ` Takashi Iwai
  2019-02-20 12:13   ` Applied "ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser" to the asoc tree Mark Brown
  2019-02-19 15:46 ` [PATCH 4/6] ASoC: qcom: Fix of-node refcount unbalance in apq8016_sbc_parse_of() Takashi Iwai
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Takashi Iwai @ 2019-02-19 15:46 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Kuninori Morimoto

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

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 4/6] ASoC: qcom: Fix of-node refcount unbalance in apq8016_sbc_parse_of()
  2019-02-19 15:46 [PATCH 0/6] ASoC: Fix of-node refcount unbalance Takashi Iwai
                   ` (2 preceding siblings ...)
  2019-02-19 15:46 ` [PATCH 3/6] ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser Takashi Iwai
@ 2019-02-19 15:46 ` 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
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 17+ messages in thread
From: Takashi Iwai @ 2019-02-19 15:46 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Banajit Goswami, Patrick Lai

The apq8016 driver leaves the of-node refcount at aborting from the
loop of for_each_child_of_node() in the error path.  Not only the
iterator node of for_each_child_of_node(), the children nodes referred
from it for codec and cpu have to be properly unreferenced.

Fixes: bdb052e81f62 ("ASoC: qcom: add apq8016 sound card support")
Cc: Patrick Lai <plai@codeaurora.org>
Cc: Banajit Goswami <bgoswami@codeaurora.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---

Only compile-tested.  Please review carefully.  Thanks!

 sound/soc/qcom/apq8016_sbc.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/sound/soc/qcom/apq8016_sbc.c b/sound/soc/qcom/apq8016_sbc.c
index 1dd23bba1bed..4b559932adc3 100644
--- a/sound/soc/qcom/apq8016_sbc.c
+++ b/sound/soc/qcom/apq8016_sbc.c
@@ -164,41 +164,52 @@ static struct apq8016_sbc_data *apq8016_sbc_parse_of(struct snd_soc_card *card)
 
 		if (!cpu || !codec) {
 			dev_err(dev, "Can't find cpu/codec DT node\n");
-			return ERR_PTR(-EINVAL);
+			ret = -EINVAL;
+			goto error;
 		}
 
 		link->cpu_of_node = of_parse_phandle(cpu, "sound-dai", 0);
 		if (!link->cpu_of_node) {
 			dev_err(card->dev, "error getting cpu phandle\n");
-			return ERR_PTR(-EINVAL);
+			ret = -EINVAL;
+			goto error;
 		}
 
 		ret = snd_soc_of_get_dai_name(cpu, &link->cpu_dai_name);
 		if (ret) {
 			dev_err(card->dev, "error getting cpu dai name\n");
-			return ERR_PTR(ret);
+			goto error;
 		}
 
 		ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
 
 		if (ret < 0) {
 			dev_err(card->dev, "error getting codec dai name\n");
-			return ERR_PTR(ret);
+			goto error;
 		}
 
 		link->platform_of_node = link->cpu_of_node;
 		ret = of_property_read_string(np, "link-name", &link->name);
 		if (ret) {
 			dev_err(card->dev, "error getting codec dai_link name\n");
-			return ERR_PTR(ret);
+			goto error;
 		}
 
 		link->stream_name = link->name;
 		link->init = apq8016_sbc_dai_init;
 		link++;
+
+		of_node_put(cpu);
+		of_node_put(codec);
 	}
 
 	return data;
+
+ error:
+	of_node_put(np);
+	of_node_put(cpu);
+	of_node_put(codec);
+	return ERR_PTR(ret);
 }
 
 static const struct snd_soc_dapm_widget apq8016_sbc_dapm_widgets[] = {
-- 
2.16.4

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 5/6] ASoC: qcom: Fix of-node refcount unbalance in qcom_snd_parse_of()
  2019-02-19 15:46 [PATCH 0/6] ASoC: Fix of-node refcount unbalance Takashi Iwai
                   ` (3 preceding siblings ...)
  2019-02-19 15:46 ` [PATCH 4/6] ASoC: qcom: Fix of-node refcount unbalance in apq8016_sbc_parse_of() Takashi Iwai
@ 2019-02-19 15:46 ` 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-20  0:27 ` [PATCH 0/6] ASoC: Fix of-node refcount unbalance Kuninori Morimoto
  6 siblings, 1 reply; 17+ messages in thread
From: Takashi Iwai @ 2019-02-19 15:46 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel, Banajit Goswami, Patrick Lai

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: c25e295cd77b ("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: Takashi Iwai <tiwai@suse.de>
---

Only compile-tested.  Please review carefully.  Thanks!

 sound/soc/qcom/common.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/sound/soc/qcom/common.c b/sound/soc/qcom/common.c
index 4715527054e5..5661025e8cec 100644
--- a/sound/soc/qcom/common.c
+++ b/sound/soc/qcom/common.c
@@ -42,6 +42,9 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 	link = card->dai_link;
 	for_each_child_of_node(dev->of_node, np) {
 		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) {
 			dev_err(dev, "Can't find cpu DT node\n");
 			ret = -EINVAL;
@@ -63,8 +66,6 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 			goto err;
 		}
 
-		platform = of_get_child_by_name(np, "platform");
-		codec = of_get_child_by_name(np, "codec");
 		if (codec && platform) {
 			link->platform_of_node = of_parse_phandle(platform,
 					"sound-dai",
@@ -100,10 +101,15 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 		link->dpcm_capture = 1;
 		link->stream_name = link->name;
 		link++;
+
+		of_node_put(cpu);
+		of_node_put(codec);
+		of_node_put(platform);
 	}
 
 	return 0;
 err:
+	of_node_put(np);
 	of_node_put(cpu);
 	of_node_put(codec);
 	of_node_put(platform);
-- 
2.16.4

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [PATCH 6/6] ASoC: samsung: Fix of-node refcount unbalance in odroid_audio_probe()
  2019-02-19 15:46 [PATCH 0/6] ASoC: Fix of-node refcount unbalance Takashi Iwai
                   ` (4 preceding siblings ...)
  2019-02-19 15:46 ` [PATCH 5/6] ASoC: qcom: Fix of-node refcount unbalance in qcom_snd_parse_of() Takashi Iwai
@ 2019-02-19 15:46 ` Takashi Iwai
  2019-02-19 16:36   ` Sylwester Nawrocki
  2019-02-20  0:27 ` [PATCH 0/6] ASoC: Fix of-node refcount unbalance Kuninori Morimoto
  6 siblings, 1 reply; 17+ messages in thread
From: Takashi Iwai @ 2019-02-19 15:46 UTC (permalink / raw)
  To: Mark Brown
  Cc: Sangbeom Kim, alsa-devel, Sylwester Nawrocki, Krzysztof Kozlowski

odroid_audio_probe() leaves of-nodes without unreferenced after use.
Fix it by shuffling some code a bit and add the missing of_node_put()
calls accordingly.

Fixes: aba611fc4c69 ("ASoC: samsung: Add Odroid ASoC machine driver")
Cc: Krzysztof Kozlowski <krzk@kernel.org>
Cc: Sangbeom Kim <sbkim73@samsung.com>
Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
---

Only compile-tested.  Please review carefully.  Thanks!

 sound/soc/samsung/odroid.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sound/soc/samsung/odroid.c b/sound/soc/samsung/odroid.c
index e7b371b07230..c96fbbc8c7cc 100644
--- a/sound/soc/samsung/odroid.c
+++ b/sound/soc/samsung/odroid.c
@@ -140,14 +140,14 @@ static int odroid_audio_probe(struct platform_device *pdev)
 	card->num_links = 1;
 
 	cpu = of_get_child_by_name(dev->of_node, "cpu");
-	codec = of_get_child_by_name(dev->of_node, "codec");
-
 	link->cpu_of_node = of_parse_phandle(cpu, "sound-dai", 0);
+	of_node_put(cpu);
 	if (!link->cpu_of_node) {
 		dev_err(dev, "Failed parsing cpu/sound-dai property\n");
 		return -EINVAL;
 	}
 
+	codec = of_get_child_by_name(dev->of_node, "codec");
 	ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
 	if (ret < 0)
 		goto err_put_codec_n;
@@ -186,6 +186,7 @@ static int odroid_audio_probe(struct platform_device *pdev)
 	of_node_put(link->cpu_of_node);
 err_put_codec_n:
 	snd_soc_of_put_dai_link_codecs(link);
+	of_node_put(codec);
 	return ret;
 }
 
-- 
2.16.4

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 6/6] ASoC: samsung: Fix of-node refcount unbalance in odroid_audio_probe()
  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
  0 siblings, 1 reply; 17+ messages in thread
From: Sylwester Nawrocki @ 2019-02-19 16:36 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Sangbeom Kim, alsa-devel, Mark Brown, Krzysztof Kozlowski

On 2/19/19 16:46, Takashi Iwai wrote:
> odroid_audio_probe() leaves of-nodes without unreferenced after use.
> Fix it by shuffling some code a bit and add the missing of_node_put()
> calls accordingly.
> 
> Fixes: aba611fc4c69 ("ASoC: samsung: Add Odroid ASoC machine driver")
> Cc: Krzysztof Kozlowski <krzk@kernel.org>
> Cc: Sangbeom Kim <sbkim73@samsung.com>
> Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
> 
> Only compile-tested.  Please review carefully.  Thanks!
Thanks for the patch. Current code for 5.1 is a bit different and we 
may now need something like:

----8<----
diff --git a/sound/soc/samsung/odroid.c b/sound/soc/samsung/odroid.c
index bd2c5163dc7f..c3b0f6c612cb 100644
--- a/sound/soc/samsung/odroid.c
+++ b/sound/soc/samsung/odroid.c
@@ -257,27 +257,31 @@ static int odroid_audio_probe(struct platform_device *pdev)
 		ret = of_parse_phandle_with_args(cpu, "sound-dai",
 						 "#sound-dai-cells", i, &args);
 		if (ret < 0)
-			return ret;
+			break;
 
 		if (!args.np) {
 			dev_err(dev, "sound-dai property parse error: %d\n", ret);
-			return -EINVAL;
+			ret = -EINVAL;
+			break;
 		}
 
 		ret = snd_soc_get_dai_name(&args, &link->cpu_dai_name);
 		of_node_put(args.np);
 
 		if (ret < 0)
-			return ret;
+			break;
 	}
+	if (ret == 0)
+		cpu_dai = of_parse_phandle(cpu, "sound-dai", 0);
 
-	cpu_dai = of_parse_phandle(cpu, "sound-dai", 0);
 	of_node_put(cpu);
 	of_node_put(codec);
+	if (ret < 0)
+		return ret;
 
 	ret = snd_soc_of_get_dai_link_codecs(dev, codec, codec_link);
 	if (ret < 0)
-		goto err_put_codec_n;
+		goto err_put_cpu_dai;
 
 	/* Set capture capability only for boards with the MAX98090 CODEC */
 	if (codec_link->num_codecs > 1) {
@@ -288,7 +292,7 @@ static int odroid_audio_probe(struct platform_device *pdev)
 	priv->sclk_i2s = of_clk_get_by_name(cpu_dai, "i2s_opclk1");
 	if (IS_ERR(priv->sclk_i2s)) {
 		ret = PTR_ERR(priv->sclk_i2s);
-		goto err_put_codec_n;
+		goto err_put_cpu_dai;
 	}
 
 	priv->clk_i2s_bus = of_clk_get_by_name(cpu_dai, "iis");
@@ -310,7 +314,8 @@ static int odroid_audio_probe(struct platform_device *pdev)
 	clk_put(priv->clk_i2s_bus);
 err_put_sclk:
 	clk_put(priv->sclk_i2s);
-err_put_codec_n:
+err_put_cpu_dai:
+	of_node_put(cpu_dai);
 	snd_soc_of_put_dai_link_codecs(codec_link);
 	return ret;
 }
----8<----

-- 
Thanks,
Sylwester

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [PATCH 0/6] ASoC: Fix of-node refcount unbalance
  2019-02-19 15:46 [PATCH 0/6] ASoC: Fix of-node refcount unbalance Takashi Iwai
                   ` (5 preceding siblings ...)
  2019-02-19 15:46 ` [PATCH 6/6] ASoC: samsung: Fix of-node refcount unbalance in odroid_audio_probe() Takashi Iwai
@ 2019-02-20  0:27 ` Kuninori Morimoto
  6 siblings, 0 replies; 17+ messages in thread
From: Kuninori Morimoto @ 2019-02-20  0:27 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, Mark Brown


Hi

> Takashi Iwai (6):
>   ASoC: fsl: Fix of-node refcount unbalance in fsl_ssi_probe_from_dt()
>   ASoC: simple-card: Fix missing of_node_put() at simple_dai_link_of()
>   ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser
>   ASoC: qcom: Fix of-node refcount unbalance in apq8016_sbc_parse_of()
>   ASoC: qcom: Fix of-node refcount unbalance in qcom_snd_parse_of()
>   ASoC: samsung: Fix of-node refcount unbalance in odroid_audio_probe()

For simple-card fixes

Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

# I want to have sanity-check method for it...

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 1/6] ASoC: fsl: Fix of-node refcount unbalance in fsl_ssi_probe_from_dt()
  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
  1 sibling, 0 replies; 17+ messages in thread
From: Nicolin Chen @ 2019-02-20  5:29 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, Mark Brown, Fabio Estevam, Timur Tabi, Xiubo Li

On Tue, Feb 19, 2019 at 04:46:47PM +0100, Takashi Iwai wrote:
> The node obtained from of_find_node_by_path() has to be unreferenced
> after the use, but we forgot it for the root node.
> 
> Fixes: f0fba2ad1b6b ("ASoC: multi-component - ASoC Multi-Component Support")
> Cc: Timur Tabi <timur@kernel.org>
> Cc: Nicolin Chen <nicoleotsuka@gmail.com>

Acked-by: Nicolin Chen <nicoleotsuka@gmail.com>

> Cc: Xiubo Li <Xiubo.Lee@gmail.com>
> Cc: Fabio Estevam <festevam@gmail.com>
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> ---
> 
> Only compile-tested.  Please review carefully.  Thanks!

Ran a boot test by removing the if-condition. It'd be fine.

Thank you
Nicolin
 
>  sound/soc/fsl/fsl_ssi.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
> index 0a648229e643..09b2967befd9 100644
> --- a/sound/soc/fsl/fsl_ssi.c
> +++ b/sound/soc/fsl/fsl_ssi.c
> @@ -1439,8 +1439,10 @@ static int fsl_ssi_probe_from_dt(struct fsl_ssi *ssi)
>  	 * different name to register the device.
>  	 */
>  	if (!ssi->card_name[0] && of_get_property(np, "codec-handle", NULL)) {
> -		sprop = of_get_property(of_find_node_by_path("/"),
> -					"compatible", NULL);
> +		struct device_node *root = of_find_node_by_path("/");
> +
> +		sprop = of_get_property(root, "compatible", NULL);
> +		of_node_put(root);
>  		/* Strip "fsl," in the compatible name if applicable */
>  		p = strrchr(sprop, ',');
>  		if (p)
> -- 
> 2.16.4
> 

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 6/6] ASoC: samsung: Fix of-node refcount unbalance in odroid_audio_probe()
  2019-02-19 16:36   ` Sylwester Nawrocki
@ 2019-02-20 10:40     ` Takashi Iwai
  2019-02-20 11:06       ` Sylwester Nawrocki
  0 siblings, 1 reply; 17+ messages in thread
From: Takashi Iwai @ 2019-02-20 10:40 UTC (permalink / raw)
  To: Sylwester Nawrocki
  Cc: Sangbeom Kim, alsa-devel, Mark Brown, Krzysztof Kozlowski

On Tue, 19 Feb 2019 17:36:56 +0100,
Sylwester Nawrocki wrote:
> 
> On 2/19/19 16:46, Takashi Iwai wrote:
> > odroid_audio_probe() leaves of-nodes without unreferenced after use.
> > Fix it by shuffling some code a bit and add the missing of_node_put()
> > calls accordingly.
> > 
> > Fixes: aba611fc4c69 ("ASoC: samsung: Add Odroid ASoC machine driver")
> > Cc: Krzysztof Kozlowski <krzk@kernel.org>
> > Cc: Sangbeom Kim <sbkim73@samsung.com>
> > Cc: Sylwester Nawrocki <s.nawrocki@samsung.com>
> > Signed-off-by: Takashi Iwai <tiwai@suse.de>
> > ---
> > 
> > Only compile-tested.  Please review carefully.  Thanks!
> Thanks for the patch. Current code for 5.1 is a bit different and we 
> may now need something like:

Ah thanks, I forgot to follow asoc repo since merging to sound.git
tree in this regard.

Care to submit the patch for the latest tree from your side?


Thanks!

Takashi

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [PATCH 6/6] ASoC: samsung: Fix of-node refcount unbalance in odroid_audio_probe()
  2019-02-20 10:40     ` Takashi Iwai
@ 2019-02-20 11:06       ` Sylwester Nawrocki
  0 siblings, 0 replies; 17+ messages in thread
From: Sylwester Nawrocki @ 2019-02-20 11:06 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Sangbeom Kim, alsa-devel, Mark Brown, Krzysztof Kozlowski

On 2/20/19 11:40, Takashi Iwai wrote:
> On Tue, 19 Feb 2019 17:36:56 +0100, Sylwester Nawrocki wrote:
>> On 2/19/19 16:46, Takashi Iwai wrote:
>>> odroid_audio_probe() leaves of-nodes without unreferenced after use.
>>> Fix it by shuffling some code a bit and add the missing of_node_put()
>>> calls accordingly.

>>> Only compile-tested.  Please review carefully.  Thanks!
>> Thanks for the patch. Current code for 5.1 is a bit different and we 
>> may now need something like:
> 
> Ah thanks, I forgot to follow asoc repo since merging to sound.git
> tree in this regard.
> 
> Care to submit the patch for the latest tree from your side?

Sure, I have just posted the patch for review.

--
Regards,
Sylwester

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Applied "ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser" to the asoc tree
  2019-02-19 15:46 ` [PATCH 3/6] ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser Takashi Iwai
@ 2019-02-20 12:13   ` Mark Brown
  0 siblings, 0 replies; 17+ messages in thread
From: Mark Brown @ 2019-02-20 12:13 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, Mark Brown, Kuninori Morimoto

The patch

   ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser

has been applied to the asoc tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 0b9c9ed6dd3b61b1d3ef1638786a7216006f67c5 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Tue, 19 Feb 2019 16:46:49 +0100
Subject: [PATCH] ASoC: simple-card: Fix of-node refcount unbalance in DAI-link
 parser

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.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 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 092963e90e1e..7147bba45a2a 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.20.1

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Applied "ASoC: simple-card: Fix missing of_node_put() at simple_dai_link_of()" to the asoc tree
  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   ` Mark Brown
  0 siblings, 0 replies; 17+ messages in thread
From: Mark Brown @ 2019-02-20 12:13 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, Mark Brown, Kuninori Morimoto

The patch

   ASoC: simple-card: Fix missing of_node_put() at simple_dai_link_of()

has been applied to the asoc tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 44662f90cda7ce0b65e77a7f1eefe45fb9053a4e Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Tue, 19 Feb 2019 16:46:48 +0100
Subject: [PATCH] ASoC: simple-card: Fix missing of_node_put() at
 simple_dai_link_of()

We forgot to unreference the platform node object obtained from
of_get_child_by_name().  This leads to the unbalance of node
refcount.

Fixes: e0ae225b7e96 ("ASoC: simple-card: support platform in dts parse")
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/generic/simple-card.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c
index dc18c4492955..092963e90e1e 100644
--- a/sound/soc/generic/simple-card.c
+++ b/sound/soc/generic/simple-card.c
@@ -421,6 +421,7 @@ static int simple_dai_link_of(struct simple_priv *priv,
 	asoc_simple_card_canonicalize_platform(dai_link);
 
 dai_link_of_err:
+	of_node_put(plat);
 	of_node_put(node);
 
 	return ret;
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Applied "ASoC: fsl: Fix of-node refcount unbalance in fsl_ssi_probe_from_dt()" to the asoc tree
  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   ` Mark Brown
  1 sibling, 0 replies; 17+ messages in thread
From: Mark Brown @ 2019-02-20 12:13 UTC (permalink / raw)
  To: Takashi Iwai
  Cc: alsa-devel, Timur Tabi, Xiubo Li, Nicolin Chen, Mark Brown,
	Fabio Estevam

The patch

   ASoC: fsl: Fix of-node refcount unbalance in fsl_ssi_probe_from_dt()

has been applied to the asoc tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 2757970f6d0d0a112247600b23d38c0c728ceeb3 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Tue, 19 Feb 2019 16:46:47 +0100
Subject: [PATCH] ASoC: fsl: Fix of-node refcount unbalance in
 fsl_ssi_probe_from_dt()

The node obtained from of_find_node_by_path() has to be unreferenced
after the use, but we forgot it for the root node.

Fixes: f0fba2ad1b6b ("ASoC: multi-component - ASoC Multi-Component Support")
Cc: Timur Tabi <timur@kernel.org>
Cc: Nicolin Chen <nicoleotsuka@gmail.com>
Cc: Xiubo Li <Xiubo.Lee@gmail.com>
Cc: Fabio Estevam <festevam@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Acked-by: Nicolin Chen <nicoleotsuka@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/fsl/fsl_ssi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index 0a648229e643..09b2967befd9 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -1439,8 +1439,10 @@ static int fsl_ssi_probe_from_dt(struct fsl_ssi *ssi)
 	 * different name to register the device.
 	 */
 	if (!ssi->card_name[0] && of_get_property(np, "codec-handle", NULL)) {
-		sprop = of_get_property(of_find_node_by_path("/"),
-					"compatible", NULL);
+		struct device_node *root = of_find_node_by_path("/");
+
+		sprop = of_get_property(root, "compatible", NULL);
+		of_node_put(root);
 		/* Strip "fsl," in the compatible name if applicable */
 		p = strrchr(sprop, ',');
 		if (p)
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Applied "ASoC: qcom: Fix of-node refcount unbalance in qcom_snd_parse_of()" to the asoc tree
  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   ` Mark Brown
  0 siblings, 0 replies; 17+ messages in thread
From: Mark Brown @ 2019-02-20 17:52 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Patrick Lai, Banajit Goswami, Mark Brown, alsa-devel

The patch

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

has been applied to the asoc tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 70b773219a32c7b8f3e53e041bc023ad99fd81f4 Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Tue, 19 Feb 2019 16:46:51 +0100
Subject: [PATCH] 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: c25e295cd77b ("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: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/qcom/common.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/sound/soc/qcom/common.c b/sound/soc/qcom/common.c
index 4715527054e5..5661025e8cec 100644
--- a/sound/soc/qcom/common.c
+++ b/sound/soc/qcom/common.c
@@ -42,6 +42,9 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 	link = card->dai_link;
 	for_each_child_of_node(dev->of_node, np) {
 		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) {
 			dev_err(dev, "Can't find cpu DT node\n");
 			ret = -EINVAL;
@@ -63,8 +66,6 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 			goto err;
 		}
 
-		platform = of_get_child_by_name(np, "platform");
-		codec = of_get_child_by_name(np, "codec");
 		if (codec && platform) {
 			link->platform_of_node = of_parse_phandle(platform,
 					"sound-dai",
@@ -100,10 +101,15 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
 		link->dpcm_capture = 1;
 		link->stream_name = link->name;
 		link++;
+
+		of_node_put(cpu);
+		of_node_put(codec);
+		of_node_put(platform);
 	}
 
 	return 0;
 err:
+	of_node_put(np);
 	of_node_put(cpu);
 	of_node_put(codec);
 	of_node_put(platform);
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Applied "ASoC: qcom: Fix of-node refcount unbalance in apq8016_sbc_parse_of()" to the asoc tree
  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   ` Mark Brown
  0 siblings, 0 replies; 17+ messages in thread
From: Mark Brown @ 2019-02-20 17:52 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: Patrick Lai, Banajit Goswami, Mark Brown, alsa-devel

The patch

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

has been applied to the asoc tree at

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From 8d1667200850f8753c0265fa4bd25c9a6e5f94ce Mon Sep 17 00:00:00 2001
From: Takashi Iwai <tiwai@suse.de>
Date: Tue, 19 Feb 2019 16:46:50 +0100
Subject: [PATCH] ASoC: qcom: Fix of-node refcount unbalance in
 apq8016_sbc_parse_of()

The apq8016 driver leaves the of-node refcount at aborting from the
loop of for_each_child_of_node() in the error path.  Not only the
iterator node of for_each_child_of_node(), the children nodes referred
from it for codec and cpu have to be properly unreferenced.

Fixes: bdb052e81f62 ("ASoC: qcom: add apq8016 sound card support")
Cc: Patrick Lai <plai@codeaurora.org>
Cc: Banajit Goswami <bgoswami@codeaurora.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/qcom/apq8016_sbc.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

diff --git a/sound/soc/qcom/apq8016_sbc.c b/sound/soc/qcom/apq8016_sbc.c
index 1dd23bba1bed..4b559932adc3 100644
--- a/sound/soc/qcom/apq8016_sbc.c
+++ b/sound/soc/qcom/apq8016_sbc.c
@@ -164,41 +164,52 @@ static struct apq8016_sbc_data *apq8016_sbc_parse_of(struct snd_soc_card *card)
 
 		if (!cpu || !codec) {
 			dev_err(dev, "Can't find cpu/codec DT node\n");
-			return ERR_PTR(-EINVAL);
+			ret = -EINVAL;
+			goto error;
 		}
 
 		link->cpu_of_node = of_parse_phandle(cpu, "sound-dai", 0);
 		if (!link->cpu_of_node) {
 			dev_err(card->dev, "error getting cpu phandle\n");
-			return ERR_PTR(-EINVAL);
+			ret = -EINVAL;
+			goto error;
 		}
 
 		ret = snd_soc_of_get_dai_name(cpu, &link->cpu_dai_name);
 		if (ret) {
 			dev_err(card->dev, "error getting cpu dai name\n");
-			return ERR_PTR(ret);
+			goto error;
 		}
 
 		ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
 
 		if (ret < 0) {
 			dev_err(card->dev, "error getting codec dai name\n");
-			return ERR_PTR(ret);
+			goto error;
 		}
 
 		link->platform_of_node = link->cpu_of_node;
 		ret = of_property_read_string(np, "link-name", &link->name);
 		if (ret) {
 			dev_err(card->dev, "error getting codec dai_link name\n");
-			return ERR_PTR(ret);
+			goto error;
 		}
 
 		link->stream_name = link->name;
 		link->init = apq8016_sbc_dai_init;
 		link++;
+
+		of_node_put(cpu);
+		of_node_put(codec);
 	}
 
 	return data;
+
+ error:
+	of_node_put(np);
+	of_node_put(cpu);
+	of_node_put(codec);
+	return ERR_PTR(ret);
 }
 
 static const struct snd_soc_dapm_widget apq8016_sbc_dapm_widgets[] = {
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2019-02-20 17:52 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 3/6] ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser Takashi Iwai
2019-02-20 12:13   ` Applied "ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser" to the asoc tree 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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.