Skip to contentSkip to conversation

ASoC: Fix of-node refcount unbalance

PATCH In review Takashi Iwai 5 participants 17 messages Feb 19, 2019 – Feb 20, 2019

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover ASoC: Fix of-node refcount unbalance

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(-)
Signature · 1 line
2.16.4
#1 lore raw

PATCH 1/6 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 <[email protected]>
Cc Nicolin Chen <[email protected]>
Cc Xiubo Li <[email protected]>
Cc Fabio Estevam <[email protected]>

---

Only compile-tested. Please review carefully. Thanks!

 sound/soc/fsl/fsl_ssi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
sound/soc/fsl/fsl_ssi.c +4 -2
index 0a648229e643..09b2967befd9 100644
@@ -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)
Signature · 1 line
2.16.4
reviewer Acked-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] ASoC: fsl: Fix of-node refcount unbalance in fsl_ssi_probe_from_dt()

Quoted 6 lines · Takashi Iwai

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 <[email protected]>
Cc Nicolin Chen <[email protected]>
Quoted 6 lines
Cc Xiubo Li <[email protected]>
Cc Fabio Estevam <[email protected]>

---

Only compile-tested. Please review carefully. Thanks!

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

Thank you
Nicolin

Quoted 23 lines
 sound/soc/fsl/fsl_ssi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
sound/soc/fsl/fsl_ssi.c +4 -2
index 0a648229e643..09b2967befd9 100644
@@ -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)
Signature · 1 line
2.16.4
maintainer
#3 lore raw

Applied "ASoC: fsl: Fix of-node refcount unbalance in fsl_ssi_probe_from_dt()" to the asoc tree

In reply to Takashi Iwai

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

Quoted 1 line

From 2757970f6d0d0a112247600b23d38c0c728ceeb3 Mon Sep 17 00:00:00 2001

From: Takashi Iwai <[email protected]>
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 <[email protected]>
Cc Nicolin Chen <[email protected]>
Cc Xiubo Li <[email protected]>
Cc Fabio Estevam <[email protected]>
---
 sound/soc/fsl/fsl_ssi.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
sound/soc/fsl/fsl_ssi.c +4 -2
index 0a648229e643..09b2967befd9 100644
@@ -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)
Signature · 1 line
2.20.1
#4 lore raw

PATCH 2/6 ASoC: simple-card: Fix missing of_node_put() at simple_dai_link_of()

In reply to Takashi Iwai

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 <[email protected]>

---

Only compile-tested. Please review carefully. Thanks!

 sound/soc/generic/simple-card.c | 1 +
 1 file changed, 1 insertion(+)
sound/soc/generic/simple-card.c +1 -0
index 08df261024cf..3e677dd1137e 100644
@@ -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;
Signature · 1 line
2.16.4
maintainer
#5 lore raw

Applied "ASoC: simple-card: Fix missing of_node_put() at simple_dai_link_of()" to the asoc tree

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

Quoted 1 line

From 44662f90cda7ce0b65e77a7f1eefe45fb9053a4e Mon Sep 17 00:00:00 2001

From: Takashi Iwai <[email protected]>
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")
---
 sound/soc/generic/simple-card.c | 1 +
 1 file changed, 1 insertion(+)
sound/soc/generic/simple-card.c +1 -0
index dc18c4492955..092963e90e1e 100644
@@ -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;
Signature · 1 line
2.20.1
#6 lore raw

PATCH 3/6 ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser

In reply to Takashi Iwai

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 <[email protected]>

---

Only compile-tested. Please review carefully. Thanks!

 sound/soc/generic/simple-card.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
sound/soc/generic/simple-card.c +12 -6
index 3e677dd1137e..30ae0a5281b3 100644
@@ -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,
Signature · 1 line
2.16.4
maintainer
#7 lore raw

Applied "ASoC: simple-card: Fix of-node refcount unbalance in DAI-link parser" to the asoc tree

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

Quoted 1 line

From 0b9c9ed6dd3b61b1d3ef1638786a7216006f67c5 Mon Sep 17 00:00:00 2001

From: Takashi Iwai <[email protected]>
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.

---
 sound/soc/generic/simple-card.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
sound/soc/generic/simple-card.c +12 -6
index 092963e90e1e..7147bba45a2a 100644
@@ -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,
Signature · 1 line
2.20.1
#8 lore raw

PATCH 4/6 ASoC: qcom: Fix of-node refcount unbalance in apq8016_sbc_parse_of()

In reply to Takashi Iwai

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 <[email protected]>
Cc Banajit Goswami <[email protected]>

---

Only compile-tested. Please review carefully. Thanks!

 sound/soc/qcom/apq8016_sbc.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
sound/soc/qcom/apq8016_sbc.c +16 -5
index 1dd23bba1bed..4b559932adc3 100644
@@ -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[] = {
Signature · 1 line
2.16.4
maintainer
#9 lore raw

Applied "ASoC: qcom: Fix of-node refcount unbalance in apq8016_sbc_parse_of()" to the asoc tree

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

Quoted 1 line

From 8d1667200850f8753c0265fa4bd25c9a6e5f94ce Mon Sep 17 00:00:00 2001

From: Takashi Iwai <[email protected]>
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 <[email protected]>
Cc Banajit Goswami <[email protected]>
---
 sound/soc/qcom/apq8016_sbc.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
sound/soc/qcom/apq8016_sbc.c +16 -5
index 1dd23bba1bed..4b559932adc3 100644
@@ -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[] = {
Signature · 1 line
2.20.1
#10 lore raw

PATCH 5/6 ASoC: qcom: Fix of-node refcount unbalance in qcom_snd_parse_of()

In reply to Takashi Iwai

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 <[email protected]>
Cc Banajit Goswami <[email protected]>

---

Only compile-tested. Please review carefully. Thanks!

 sound/soc/qcom/common.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
sound/soc/qcom/common.c +8 -2
index 4715527054e5..5661025e8cec 100644
@@ -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);
Signature · 1 line
2.16.4
maintainer
#11 lore raw

Applied "ASoC: qcom: Fix of-node refcount unbalance in qcom_snd_parse_of()" to the asoc tree

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

Quoted 1 line

From 70b773219a32c7b8f3e53e041bc023ad99fd81f4 Mon Sep 17 00:00:00 2001

From: Takashi Iwai <[email protected]>
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 <[email protected]>
Cc Banajit Goswami <[email protected]>
---
 sound/soc/qcom/common.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
sound/soc/qcom/common.c +8 -2
index 4715527054e5..5661025e8cec 100644
@@ -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);
Signature · 1 line
2.20.1
#12 lore raw

PATCH 6/6 ASoC: samsung: Fix of-node refcount unbalance in odroid_audio_probe()

In reply to Takashi Iwai

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 <[email protected]>
Cc Sangbeom Kim <[email protected]>
Cc Sylwester Nawrocki <[email protected]>

---

Only compile-tested. Please review carefully. Thanks!

 sound/soc/samsung/odroid.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
sound/soc/samsung/odroid.c +3 -2
index e7b371b07230..c96fbbc8c7cc 100644
@@ -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;
 }
 
Signature · 1 line
2.16.4
#13 lore raw

Re: [PATCH 6/6] ASoC: samsung: Fix of-node refcount unbalance in odroid_audio_probe()

Quoted 4 lines · Takashi Iwai

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.

Quoted 8 lines
Fixes aba611fc4c69 ("ASoC: samsung: Add Odroid ASoC machine driver")
Cc Krzysztof Kozlowski <[email protected]>
Cc Sangbeom Kim <[email protected]>
Cc Sylwester Nawrocki <[email protected]>

---

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<----

sound/soc/samsung/odroid.c +12 -7
index bd2c5163dc7f..c3b0f6c612cb 100644
@@ -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<----

Signature · 2 lines
Thanks,
Sylwester
#14 lore raw

Re: [PATCH 6/6] ASoC: samsung: Fix of-node refcount unbalance in odroid_audio_probe()

Quoted 13 lines · Sylwester Nawrocki
Quoted 11 lines · Takashi Iwai

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 <[email protected]>
Cc Sangbeom Kim <[email protected]>
Cc Sylwester Nawrocki <[email protected]>

---

Quoted 3 lines
Quoted 1 line

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

#15 lore raw

Re: [PATCH 6/6] ASoC: samsung: Fix of-node refcount unbalance in odroid_audio_probe()

Quoted 6 lines · Takashi Iwai
Quoted 4 lines · Sylwester Nawrocki
Quoted 3 lines · Takashi Iwai

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.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

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

maintainer Acked-by on the v1 series
#16 lore raw
In reply to Takashi Iwai

Hi

Quoted 7 lines

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

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