All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ladislav Michl <ladis@linux-mips.org>
To: alsa-devel@alsa-project.org
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Takashi Iwai <tiwai@suse.com>, Mark Brown <broonie@kernel.org>,
	Alexandre Belloni <alexandre.belloni@free-electrons.com>,
	SF Markus Elfring <elfring@users.sourceforge.net>
Subject: [PATCH 4/5] ASoC: sam9x5_wm8731: Fix OF node reference counting
Date: Mon, 15 Jan 2018 08:54:30 +0100	[thread overview]
Message-ID: <20180115075430.GE10762@lenoch> (raw)
In-Reply-To: <20180115075213.GA10762@lenoch>

of_node_release() is called as the destructor on a dynamically
allocated node in of_node_put(), but node pointer is still in use.
Fix that by moving of_node_put() into the error path.

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
 sound/soc/atmel/sam9x5_wm8731.c | 27 ++++++++++++---------------
 1 file changed, 12 insertions(+), 15 deletions(-)

diff --git a/sound/soc/atmel/sam9x5_wm8731.c b/sound/soc/atmel/sam9x5_wm8731.c
index 9db08826b32a..bcfb474ee0e8 100644
--- a/sound/soc/atmel/sam9x5_wm8731.c
+++ b/sound/soc/atmel/sam9x5_wm8731.c
@@ -78,7 +78,6 @@ static const struct snd_soc_dapm_widget sam9x5_dapm_widgets[] = {
 static int sam9x5_wm8731_driver_probe(struct platform_device *pdev)
 {
 	struct device_node *np = pdev->dev.of_node;
-	struct device_node *codec_np, *cpu_np;
 	struct snd_soc_card *card;
 	struct snd_soc_dai_link *dai;
 	struct sam9x5_drvdata *priv;
@@ -122,36 +121,30 @@ static int sam9x5_wm8731_driver_probe(struct platform_device *pdev)
 		goto out;
 	}
 
-	codec_np = of_parse_phandle(np, "atmel,audio-codec", 0);
-	if (!codec_np) {
+	dai->codec_of_node = of_parse_phandle(np, "atmel,audio-codec", 0);
+	if (!dai->codec_of_node) {
 		dev_err(&pdev->dev, "atmel,audio-codec node missing\n");
 		ret = -EINVAL;
 		goto out;
 	}
 
-	dai->codec_of_node = codec_np;
-
-	cpu_np = of_parse_phandle(np, "atmel,ssc-controller", 0);
-	if (!cpu_np) {
+	dai->cpu_of_node = of_parse_phandle(np, "atmel,ssc-controller", 0);
+	if (!dai->cpu_of_node) {
 		dev_err(&pdev->dev, "atmel,ssc-controller node missing\n");
 		ret = -EINVAL;
-		goto out;
+		goto out_put_codec;
 	}
-	dai->cpu_of_node = cpu_np;
-	dai->platform_of_node = cpu_np;
+	dai->platform_of_node = dai->cpu_of_node;
 
-	priv->ssc_id = of_alias_get_id(cpu_np, "ssc");
+	priv->ssc_id = of_alias_get_id(dai->cpu_of_node, "ssc");
 
 	ret = atmel_ssc_set_audio(priv->ssc_id);
 	if (ret != 0) {
 		dev_err(&pdev->dev, "Failed to set SSC %d for audio: %d\n",
 			ret, priv->ssc_id);
-		goto out;
+		goto out_put_cpu;
 	}
 
-	of_node_put(codec_np);
-	of_node_put(cpu_np);
-
 	ret = snd_soc_register_card(card);
 	if (ret) {
 		dev_err(&pdev->dev, "Platform device allocation failed\n");
@@ -164,6 +157,10 @@ static int sam9x5_wm8731_driver_probe(struct platform_device *pdev)
 
 out_put_audio:
 	atmel_ssc_put_audio(priv->ssc_id);
+out_put_cpu:
+	of_node_put(dai->cpu_of_node);
+out_put_codec:
+	of_node_put(dai->codec_of_node);
 out:
 	return ret;
 }
-- 
2.15.1

  parent reply	other threads:[~2018-01-15  7:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-15  7:52 [PATCH 0/5] ASoC: (minor) atmel cleanup Ladislav Michl
2018-01-15  7:52 ` [PATCH 1/5] ASoC: sam9g20_wm8731: use dev_*() logging functions Ladislav Michl
2018-01-22 12:26   ` Applied "ASoC: sam9g20_wm8731: use dev_*() logging functions" to the asoc tree Mark Brown
2018-01-15  7:53 ` [PATCH 2/5] ASoC: sam9x5_wm8731: Drop 'ASoC' prefix from error messages Ladislav Michl
2018-01-22 12:26   ` Applied "ASoC: sam9x5_wm8731: Drop 'ASoC' prefix from error messages" to the asoc tree Mark Brown
2018-01-15  7:53 ` [PATCH 3/5] ASoC: sam9x5_wm8731: Return -ENODEV when probe does not find OF node Ladislav Michl
2018-01-15  8:20   ` Alexandre Belloni
2018-01-15  9:11     ` Ladislav Michl
2018-01-15  9:22       ` Alexandre Belloni
2018-01-15  7:54 ` Ladislav Michl [this message]
2018-01-15  8:46   ` [PATCH 4/5] ASoC: sam9x5_wm8731: Fix OF node reference counting Alexandre Belloni
2018-01-15  9:08     ` Ladislav Michl
2018-01-15  7:54 ` [PATCH 5/5] ASoC: atmel_wm8904: Return -ENODEV when probe does not find OF node Ladislav Michl

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=20180115075430.GE10762@lenoch \
    --to=ladis@linux-mips.org \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=elfring@users.sourceforge.net \
    --cc=lgirdwood@gmail.com \
    --cc=nicolas.ferre@microchip.com \
    --cc=tiwai@suse.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 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.