Skip to contentSkip to conversation

ASoC: mediatek: common: Fix refcount leak in parse_dai_link_info

PATCH In review Aashish Sharma 5 participants 6 messages Apr 11, 2023

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

PATCH 1/1 ASoC: mediatek: common: Fix refcount leak in parse_dai_link_info

Add missing of_node_put()s before the returns to balance of_node_get()s and of_node_put()s, which may get unbalanced in case the for loop 'for_each_available_child_of_node' returns early.

Fixes 4302187d955f ("ASoC: mediatek: common: add soundcard driver common code")
---
 sound/soc/mediatek/common/mtk-soundcard-driver.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
sound/soc/mediatek/common/mtk-soundcard-driver.c +9 -3
index 7c55c2cb1f21..738093451ccb 100644
@@ -47,20 +47,26 @@ int parse_dai_link_info(struct snd_soc_card *card)
 	/* Loop over all the dai link sub nodes */
 	for_each_available_child_of_node(dev->of_node, sub_node) {
 		if (of_property_read_string(sub_node, "link-name",
-					    &dai_link_name))
+					    &dai_link_name)) {
+			of_node_put(sub_node);
 			return -EINVAL;
+		}
 
 		for_each_card_prelinks(card, i, dai_link) {
 			if (!strcmp(dai_link_name, dai_link->name))
 				break;
 		}
 
-		if (i >= card->num_links)
+		if (i >= card->num_links) {
+			of_node_put(sub_node);
 			return -EINVAL;
+		}
 
 		ret = set_card_codec_info(card, sub_node, dai_link);
-		if (ret < 0)
+		if (ret < 0) {
+			of_node_put(sub_node);
 			return ret;
+		}
 	}
 
 	return 0;
Signature · 1 line
2.40.0.577.gac1e443424-goog
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Aashish Sharma

Add missing of_node_put()s before the returns to balance of_node_get()s and of_node_put()s, which may get unbalanced in case the for loop 'for_each_available_child_of_node' returns early.

Fixes 4302187d955f ("ASoC: mediatek: common: add soundcard driver common code")
Quoted 41 lines
---
 sound/soc/mediatek/common/mtk-soundcard-driver.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
sound/soc/mediatek/common/mtk-soundcard-driver.c +9 -4
index 7c55c2cb1f21..738093451ccb 100644
@@ -47,20 +47,26 @@ int parse_dai_link_info(struct snd_soc_card *card)
        /* Loop over all the dai link sub nodes */
        for_each_available_child_of_node(dev->of_node, sub_node) {
                if (of_property_read_string(sub_node, "link-name",
-                                           &dai_link_name))
+                                           &dai_link_name)) {
+                       of_node_put(sub_node);
                        return -EINVAL;
+               }
 
                for_each_card_prelinks(card, i, dai_link) {
                        if (!strcmp(dai_link_name, dai_link->name))
                                break;
                }
 
-               if (i >= card->num_links)
+               if (i >= card->num_links) {
+                       of_node_put(sub_node);
                        return -EINVAL;
+               }
 
                ret = set_card_codec_info(card, sub_node, dai_link);
-               if (ret < 0)
+               if (ret < 0) {
+                       of_node_put(sub_node);
                        return ret;
+               }
        }
 
        return 0;
--

2.40.0.577.gac1e443424-goog

Reviewed-by Guenter Roeck on v1 1/1
#2 lore raw
In reply to Aashish Sharma
Quoted 11 lines · Aashish Sharma

Add missing of_node_put()s before the returns to balance of_node_get()s and of_node_put()s, which may get unbalanced in case the for loop 'for_each_available_child_of_node' returns early.

Fixes 4302187d955f ("ASoC: mediatek: common: add soundcard driver common code")
Quoted 41 lines
---
 sound/soc/mediatek/common/mtk-soundcard-driver.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
sound/soc/mediatek/common/mtk-soundcard-driver.c +9 -4
index 7c55c2cb1f21..738093451ccb 100644
@@ -47,20 +47,26 @@ int parse_dai_link_info(struct snd_soc_card *card)
        /* Loop over all the dai link sub nodes */
        for_each_available_child_of_node(dev->of_node, sub_node) {
                if (of_property_read_string(sub_node, "link-name",
-                                           &dai_link_name))
+                                           &dai_link_name)) {
+                       of_node_put(sub_node);
                        return -EINVAL;
+               }
 
                for_each_card_prelinks(card, i, dai_link) {
                        if (!strcmp(dai_link_name, dai_link->name))
                                break;
                }
 
-               if (i >= card->num_links)
+               if (i >= card->num_links) {
+                       of_node_put(sub_node);
                        return -EINVAL;
+               }
 
                ret = set_card_codec_info(card, sub_node, dai_link);
-               if (ret < 0)
+               if (ret < 0) {
+                       of_node_put(sub_node);
                        return ret;
+               }
        }
 
        return 0;
--

2.40.0.577.gac1e443424-goog

Reviewed-by on v1 1/1
#3 lore raw
In reply to Aashish Sharma
Quoted 9 lines · Aashish Sharma

External email : Please do not click links or open attachments until you have verified the sender or the content.

Add missing of_node_put()s before the returns to balance of_node_get()s and of_node_put()s, which may get unbalanced in case the for loop 'for_each_available_child_of_node' returns early.

Quoted 6 lines
Fixes 4302187d955f ("ASoC: mediatek: common: add soundcard driver

common code")

Quoted 43 lines
---
 sound/soc/mediatek/common/mtk-soundcard-driver.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
sound/soc/mediatek/common/mtk-soundcard-driver.c +9 -3
index 7c55c2cb1f21..738093451ccb 100644
@@ -47,20 +47,26 @@ int parse_dai_link_info(struct snd_soc_card
 *card)
        /* Loop over all the dai link sub nodes */
        for_each_available_child_of_node(dev->of_node, sub_node) {
                if (of_property_read_string(sub_node, "link-name",
-                                           &dai_link_name))
+                                           &dai_link_name)) {
+                       of_node_put(sub_node);
                        return -EINVAL;
+               }
 
                for_each_card_prelinks(card, i, dai_link) {
                        if (!strcmp(dai_link_name, dai_link->name))
                                break;
                }
 
-               if (i >= card->num_links)
+               if (i >= card->num_links) {
+                       of_node_put(sub_node);
                        return -EINVAL;
+               }
 
                ret = set_card_codec_info(card, sub_node, dai_link);
-               if (ret < 0)
+               if (ret < 0) {
+                       of_node_put(sub_node);
                        return ret;
+               }
        }
 
        return 0;

--
2.40.0.577.gac1e443424-goog

Reviewed-by Trevor Wu on v1 1/1
#4 lore raw
In reply to Aashish Sharma
Quoted 9 lines · Aashish Sharma

External email : Please do not click links or open attachments until you have verified the sender or the content.

Add missing of_node_put()s before the returns to balance of_node_get()s and of_node_put()s, which may get unbalanced in case the for loop 'for_each_available_child_of_node' returns early.

Quoted 6 lines
Fixes 4302187d955f ("ASoC: mediatek: common: add soundcard driver

common code")

Quoted 43 lines
---
 sound/soc/mediatek/common/mtk-soundcard-driver.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
sound/soc/mediatek/common/mtk-soundcard-driver.c +9 -3
index 7c55c2cb1f21..738093451ccb 100644
@@ -47,20 +47,26 @@ int parse_dai_link_info(struct snd_soc_card
 *card)
        /* Loop over all the dai link sub nodes */
        for_each_available_child_of_node(dev->of_node, sub_node) {
                if (of_property_read_string(sub_node, "link-name",
-                                           &dai_link_name))
+                                           &dai_link_name)) {
+                       of_node_put(sub_node);
                        return -EINVAL;
+               }
 
                for_each_card_prelinks(card, i, dai_link) {
                        if (!strcmp(dai_link_name, dai_link->name))
                                break;
                }
 
-               if (i >= card->num_links)
+               if (i >= card->num_links) {
+                       of_node_put(sub_node);
                        return -EINVAL;
+               }
 
                ret = set_card_codec_info(card, sub_node, dai_link);
-               if (ret < 0)
+               if (ret < 0) {
+                       of_node_put(sub_node);
                        return ret;
+               }
        }
 
        return 0;

--
2.40.0.577.gac1e443424-goog

maintainer
#5 lore raw
In reply to Aashish Sharma
Quoted 6 lines · Aashish Sharma

Add missing of_node_put()s before the returns to balance of_node_get()s and of_node_put()s, which may get unbalanced in case the for loop 'for_each_available_child_of_node' returns early.

Applied to

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

Thanks!

[1/1] ASoC: mediatek: common: Fix refcount leak in parse_dai_link_info

      commit: beed115c2ce78f990222a29abed042582df4e87c

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