linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ASoC: atmel: Fix error handling in snd_proto_probe
@ 2022-03-07 13:04 Miaoqian Lin
  2022-03-07 13:45 ` Codrin.Ciubotariu
  0 siblings, 1 reply; 4+ messages in thread
From: Miaoqian Lin @ 2022-03-07 13:04 UTC (permalink / raw)
  To: Codrin Ciubotariu, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
	Florian Meier, alsa-devel, linux-arm-kernel, linux-kernel
  Cc: linmq006

The device_node pointer is returned by of_parse_phandle()  with refcount
incremented. We should use of_node_put() on it when done.

This function only calls of_node_put() in the regular path.
And it will cause refcount leak in error paths.
Fix this by calling of_node_put() in error handling too.

Fixes: a45f8853a5f9 ("ASoC: Add driver for PROTO Audio CODEC (with a WM8731)")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
 sound/soc/atmel/mikroe-proto.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/sound/soc/atmel/mikroe-proto.c b/sound/soc/atmel/mikroe-proto.c
index 627564c18c27..9ed634ee9dfc 100644
--- a/sound/soc/atmel/mikroe-proto.c
+++ b/sound/soc/atmel/mikroe-proto.c
@@ -115,7 +115,8 @@ static int snd_proto_probe(struct platform_device *pdev)
 	cpu_np = of_parse_phandle(np, "i2s-controller", 0);
 	if (!cpu_np) {
 		dev_err(&pdev->dev, "i2s-controller missing\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto put_codec_node;
 	}
 	dai->cpus->of_node = cpu_np;
 	dai->platforms->of_node = cpu_np;
@@ -125,7 +126,8 @@ static int snd_proto_probe(struct platform_device *pdev)
 						       &bitclkmaster, &framemaster);
 	if (bitclkmaster != framemaster) {
 		dev_err(&pdev->dev, "Must be the same bitclock and frame master\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto put_cpu_node;
 	}
 	if (bitclkmaster) {
 		if (codec_np == bitclkmaster)
@@ -136,18 +138,21 @@ static int snd_proto_probe(struct platform_device *pdev)
 		dai_fmt |= snd_soc_daifmt_parse_clock_provider_as_flag(np, NULL);
 	}
 
-	of_node_put(bitclkmaster);
-	of_node_put(framemaster);
-	dai->dai_fmt = dai_fmt;
 
-	of_node_put(codec_np);
-	of_node_put(cpu_np);
+	dai->dai_fmt = dai_fmt;
 
 	ret = snd_soc_register_card(&snd_proto);
 	if (ret)
 		dev_err_probe(&pdev->dev, ret,
 			"snd_soc_register_card() failed\n");
 
+
+put_cpu_node:
+	of_node_put(bitclkmaster);
+	of_node_put(framemaster);
+	of_node_put(cpu_np);
+put_codec_node:
+	of_node_put(codec_np);
 	return ret;
 }
 
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH] ASoC: atmel: Fix error handling in snd_proto_probe
  2022-03-07 13:04 [PATCH] ASoC: atmel: Fix error handling in snd_proto_probe Miaoqian Lin
@ 2022-03-07 13:45 ` Codrin.Ciubotariu
  2022-03-08  1:39   ` [PATCH v2] " Miaoqian Lin
  0 siblings, 1 reply; 4+ messages in thread
From: Codrin.Ciubotariu @ 2022-03-07 13:45 UTC (permalink / raw)
  To: linmq006, lgirdwood, broonie, perex, tiwai, Nicolas.Ferre,
	alexandre.belloni, Claudiu.Beznea, florian.meier, alsa-devel,
	linux-arm-kernel, linux-kernel

On 07.03.2022 15:04, Miaoqian Lin wrote:
> @@ -136,18 +138,21 @@ static int snd_proto_probe(struct platform_device *pdev)
>                  dai_fmt |= snd_soc_daifmt_parse_clock_provider_as_flag(np, NULL);
>          }
> 
> -       of_node_put(bitclkmaster);
> -       of_node_put(framemaster);
> -       dai->dai_fmt = dai_fmt;
> 
> -       of_node_put(codec_np);
> -       of_node_put(cpu_np);
> +       dai->dai_fmt = dai_fmt;

looks like there is an extra line that remains here

With this addressed, you can add:

Reviewed-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>

Thanks!
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH v2] ASoC: atmel: Fix error handling in snd_proto_probe
  2022-03-07 13:45 ` Codrin.Ciubotariu
@ 2022-03-08  1:39   ` Miaoqian Lin
  2022-03-08 17:20     ` Mark Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Miaoqian Lin @ 2022-03-08  1:39 UTC (permalink / raw)
  To: Codrin Ciubotariu, Liam Girdwood, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Nicolas Ferre, Alexandre Belloni, Claudiu Beznea,
	Florian Meier, alsa-devel, linux-arm-kernel, linux-kernel
  Cc: linmq006

The device_node pointer is returned by of_parse_phandle()  with refcount
incremented. We should use of_node_put() on it when done.

This function only calls of_node_put() in the regular path.
And it will cause refcount leak in error paths.
Fix this by calling of_node_put() in error handling too.

Fixes: a45f8853a5f9 ("ASoC: Add driver for PROTO Audio CODEC (with a WM8731)")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Reviewed-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
---
changes in v2:
- remove extra line.
---
 sound/soc/atmel/mikroe-proto.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/sound/soc/atmel/mikroe-proto.c b/sound/soc/atmel/mikroe-proto.c
index 627564c18c27..ce46d8a0b7e4 100644
--- a/sound/soc/atmel/mikroe-proto.c
+++ b/sound/soc/atmel/mikroe-proto.c
@@ -115,7 +115,8 @@ static int snd_proto_probe(struct platform_device *pdev)
 	cpu_np = of_parse_phandle(np, "i2s-controller", 0);
 	if (!cpu_np) {
 		dev_err(&pdev->dev, "i2s-controller missing\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto put_codec_node;
 	}
 	dai->cpus->of_node = cpu_np;
 	dai->platforms->of_node = cpu_np;
@@ -125,7 +126,8 @@ static int snd_proto_probe(struct platform_device *pdev)
 						       &bitclkmaster, &framemaster);
 	if (bitclkmaster != framemaster) {
 		dev_err(&pdev->dev, "Must be the same bitclock and frame master\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto put_cpu_node;
 	}
 	if (bitclkmaster) {
 		if (codec_np == bitclkmaster)
@@ -136,18 +138,20 @@ static int snd_proto_probe(struct platform_device *pdev)
 		dai_fmt |= snd_soc_daifmt_parse_clock_provider_as_flag(np, NULL);
 	}
 
-	of_node_put(bitclkmaster);
-	of_node_put(framemaster);
-	dai->dai_fmt = dai_fmt;
-
-	of_node_put(codec_np);
-	of_node_put(cpu_np);
 
+	dai->dai_fmt = dai_fmt;
 	ret = snd_soc_register_card(&snd_proto);
 	if (ret)
 		dev_err_probe(&pdev->dev, ret,
 			"snd_soc_register_card() failed\n");
 
+
+put_cpu_node:
+	of_node_put(bitclkmaster);
+	of_node_put(framemaster);
+	of_node_put(cpu_np);
+put_codec_node:
+	of_node_put(codec_np);
 	return ret;
 }
 
-- 
2.17.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH v2] ASoC: atmel: Fix error handling in snd_proto_probe
  2022-03-08  1:39   ` [PATCH v2] " Miaoqian Lin
@ 2022-03-08 17:20     ` Mark Brown
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2022-03-08 17:20 UTC (permalink / raw)
  To: Jaroslav Kysela, alsa-devel, Claudiu Beznea, Florian Meier,
	Takashi Iwai, linux-kernel, linux-arm-kernel, Liam Girdwood,
	Nicolas Ferre, Alexandre Belloni, Codrin Ciubotariu, Miaoqian Lin

On Tue, 8 Mar 2022 01:39:48 +0000, Miaoqian Lin wrote:
> The device_node pointer is returned by of_parse_phandle()  with refcount
> incremented. We should use of_node_put() on it when done.
> 
> This function only calls of_node_put() in the regular path.
> And it will cause refcount leak in error paths.
> Fix this by calling of_node_put() in error handling too.
> 
> [...]

Applied to

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

Thanks!

[1/1] ASoC: atmel: Fix error handling in snd_proto_probe
      commit: b0bfaf0544d08d093d6211d7ef8816fb0b5b6c75

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

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2022-03-08 17:34 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-03-07 13:04 [PATCH] ASoC: atmel: Fix error handling in snd_proto_probe Miaoqian Lin
2022-03-07 13:45 ` Codrin.Ciubotariu
2022-03-08  1:39   ` [PATCH v2] " Miaoqian Lin
2022-03-08 17:20     ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).