All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak
@ 2021-12-14  4:00 ` Tzung-Bi Shih
  0 siblings, 0 replies; 9+ messages in thread
From: Tzung-Bi Shih @ 2021-12-14  4:00 UTC (permalink / raw)
  To: broonie, lgirdwood, perex, tiwai
  Cc: alsa-devel, tzungbi, linux-arm-kernel, linux-mediatek

The of_parse_phandle() document:
    >>> Use of_node_put() on it when done.

The driver didn't call of_node_put().  Fixes the leak.

Signed-off-by: Tzung-Bi Shih <tzungbi@google.com>
---
Hi maintainers,

Need your comments.  The patch is one of the partial fixes that I think
it makes the most sense.

Option 1. Machine driver makes sure the object is valid until registered

This patch adopts the option.  It needs snd_soc_register_card() to call
of_node_get() somewhere to hold the reference count of of_node.  However,
I failed to find similar logic in soc-core.c.

Option 2. Machine driver borrows the reference count

This is what [1] adopts.  Decreasing the reference count in device's
remove() to make sure the object is valid for whole sound card's lifecycle.

[1]: https://elixir.bootlin.com/linux/v5.16-rc5/source/sound/soc/mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c#L1065


In fact, in my test environment, CONFIG_OF_DYNAMIC is not set.  The
implementation is empty[2].

Per [3]:
    >>> Hardly any platforms need this

[2]: https://elixir.bootlin.com/linux/v5.16-rc5/source/include/linux/of.h#L125
[3]: https://elixir.bootlin.com/linux/v5.16-rc5/source/drivers/of/Kconfig#L55

I am not sure if it is worthy to find somewhere to hold the reference count
in soc-core.c but I think option 1 makes it more clear to drivers.

 sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c b/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c
index a606133951b7..24a5d0adec1b 100644
--- a/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c
+++ b/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c
@@ -1172,7 +1172,11 @@ static int mt8192_mt6359_dev_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	return devm_snd_soc_register_card(&pdev->dev, card);
+	ret = devm_snd_soc_register_card(&pdev->dev, card);
+
+	of_node_put(platform_node);
+	of_node_put(hdmi_codec);
+	return ret;
 }
 
 #ifdef CONFIG_OF
-- 
2.34.1.173.g76aa8bc2d0-goog


_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

* [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak
@ 2021-12-14  4:00 ` Tzung-Bi Shih
  0 siblings, 0 replies; 9+ messages in thread
From: Tzung-Bi Shih @ 2021-12-14  4:00 UTC (permalink / raw)
  To: broonie, lgirdwood, perex, tiwai
  Cc: tzungbi, alsa-devel, linux-mediatek, linux-arm-kernel

The of_parse_phandle() document:
    >>> Use of_node_put() on it when done.

The driver didn't call of_node_put().  Fixes the leak.

Signed-off-by: Tzung-Bi Shih <tzungbi@google.com>
---
Hi maintainers,

Need your comments.  The patch is one of the partial fixes that I think
it makes the most sense.

Option 1. Machine driver makes sure the object is valid until registered

This patch adopts the option.  It needs snd_soc_register_card() to call
of_node_get() somewhere to hold the reference count of of_node.  However,
I failed to find similar logic in soc-core.c.

Option 2. Machine driver borrows the reference count

This is what [1] adopts.  Decreasing the reference count in device's
remove() to make sure the object is valid for whole sound card's lifecycle.

[1]: https://elixir.bootlin.com/linux/v5.16-rc5/source/sound/soc/mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c#L1065


In fact, in my test environment, CONFIG_OF_DYNAMIC is not set.  The
implementation is empty[2].

Per [3]:
    >>> Hardly any platforms need this

[2]: https://elixir.bootlin.com/linux/v5.16-rc5/source/include/linux/of.h#L125
[3]: https://elixir.bootlin.com/linux/v5.16-rc5/source/drivers/of/Kconfig#L55

I am not sure if it is worthy to find somewhere to hold the reference count
in soc-core.c but I think option 1 makes it more clear to drivers.

 sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c b/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c
index a606133951b7..24a5d0adec1b 100644
--- a/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c
+++ b/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c
@@ -1172,7 +1172,11 @@ static int mt8192_mt6359_dev_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	return devm_snd_soc_register_card(&pdev->dev, card);
+	ret = devm_snd_soc_register_card(&pdev->dev, card);
+
+	of_node_put(platform_node);
+	of_node_put(hdmi_codec);
+	return ret;
 }
 
 #ifdef CONFIG_OF
-- 
2.34.1.173.g76aa8bc2d0-goog


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

* [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak
@ 2021-12-14  4:00 ` Tzung-Bi Shih
  0 siblings, 0 replies; 9+ messages in thread
From: Tzung-Bi Shih @ 2021-12-14  4:00 UTC (permalink / raw)
  To: broonie, lgirdwood, perex, tiwai
  Cc: alsa-devel, tzungbi, linux-arm-kernel, linux-mediatek

The of_parse_phandle() document:
    >>> Use of_node_put() on it when done.

The driver didn't call of_node_put().  Fixes the leak.

Signed-off-by: Tzung-Bi Shih <tzungbi@google.com>
---
Hi maintainers,

Need your comments.  The patch is one of the partial fixes that I think
it makes the most sense.

Option 1. Machine driver makes sure the object is valid until registered

This patch adopts the option.  It needs snd_soc_register_card() to call
of_node_get() somewhere to hold the reference count of of_node.  However,
I failed to find similar logic in soc-core.c.

Option 2. Machine driver borrows the reference count

This is what [1] adopts.  Decreasing the reference count in device's
remove() to make sure the object is valid for whole sound card's lifecycle.

[1]: https://elixir.bootlin.com/linux/v5.16-rc5/source/sound/soc/mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c#L1065


In fact, in my test environment, CONFIG_OF_DYNAMIC is not set.  The
implementation is empty[2].

Per [3]:
    >>> Hardly any platforms need this

[2]: https://elixir.bootlin.com/linux/v5.16-rc5/source/include/linux/of.h#L125
[3]: https://elixir.bootlin.com/linux/v5.16-rc5/source/drivers/of/Kconfig#L55

I am not sure if it is worthy to find somewhere to hold the reference count
in soc-core.c but I think option 1 makes it more clear to drivers.

 sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c b/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c
index a606133951b7..24a5d0adec1b 100644
--- a/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c
+++ b/sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c
@@ -1172,7 +1172,11 @@ static int mt8192_mt6359_dev_probe(struct platform_device *pdev)
 		return ret;
 	}
 
-	return devm_snd_soc_register_card(&pdev->dev, card);
+	ret = devm_snd_soc_register_card(&pdev->dev, card);
+
+	of_node_put(platform_node);
+	of_node_put(hdmi_codec);
+	return ret;
 }
 
 #ifdef CONFIG_OF
-- 
2.34.1.173.g76aa8bc2d0-goog


_______________________________________________
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] 9+ messages in thread

* Re: [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak
  2021-12-14  4:00 ` Tzung-Bi Shih
  (?)
@ 2021-12-23 19:39   ` Mark Brown
  -1 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2021-12-23 19:39 UTC (permalink / raw)
  To: Tzung-Bi Shih, lgirdwood, perex, tiwai
  Cc: linux-arm-kernel, alsa-devel, linux-mediatek

On Tue, 14 Dec 2021 12:00:28 +0800, Tzung-Bi Shih wrote:
> The of_parse_phandle() document:
>     >>> Use of_node_put() on it when done.
> 
> The driver didn't call of_node_put().  Fixes the leak.
> 
> 

Applied to

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

Thanks!

[1/1] ASoC: mediatek: mt8192-mt6359: fix device_node leak
      commit: 4e28491a7a198c668437f2be8a91a76aa52f20eb

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-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

* Re: [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak
@ 2021-12-23 19:39   ` Mark Brown
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2021-12-23 19:39 UTC (permalink / raw)
  To: Tzung-Bi Shih, lgirdwood, perex, tiwai
  Cc: alsa-devel, linux-mediatek, linux-arm-kernel

On Tue, 14 Dec 2021 12:00:28 +0800, Tzung-Bi Shih wrote:
> The of_parse_phandle() document:
>     >>> Use of_node_put() on it when done.
> 
> The driver didn't call of_node_put().  Fixes the leak.
> 
> 

Applied to

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

Thanks!

[1/1] ASoC: mediatek: mt8192-mt6359: fix device_node leak
      commit: 4e28491a7a198c668437f2be8a91a76aa52f20eb

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

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

* Re: [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak
@ 2021-12-23 19:39   ` Mark Brown
  0 siblings, 0 replies; 9+ messages in thread
From: Mark Brown @ 2021-12-23 19:39 UTC (permalink / raw)
  To: Tzung-Bi Shih, lgirdwood, perex, tiwai
  Cc: linux-arm-kernel, alsa-devel, linux-mediatek

On Tue, 14 Dec 2021 12:00:28 +0800, Tzung-Bi Shih wrote:
> The of_parse_phandle() document:
>     >>> Use of_node_put() on it when done.
> 
> The driver didn't call of_node_put().  Fixes the leak.
> 
> 

Applied to

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

Thanks!

[1/1] ASoC: mediatek: mt8192-mt6359: fix device_node leak
      commit: 4e28491a7a198c668437f2be8a91a76aa52f20eb

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] 9+ messages in thread

* Re: [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak
  2021-12-14  4:00 ` Tzung-Bi Shih
  (?)
@ 2021-12-24  6:21   ` Tzung-Bi Shih
  -1 siblings, 0 replies; 9+ messages in thread
From: Tzung-Bi Shih @ 2021-12-24  6:21 UTC (permalink / raw)
  To: broonie, lgirdwood, perex, tiwai
  Cc: alsa-devel, linux-mediatek, Jiaxin Yu (俞家鑫),
	linux-arm-kernel

On Tue, Dec 14, 2021 at 12:00 PM Tzung-Bi Shih <tzungbi@google.com> wrote:
> Option 1. Machine driver makes sure the object is valid until registered
>
> This patch adopts the option.  It needs snd_soc_register_card() to call
> of_node_get() somewhere to hold the reference count of of_node.  However,
> I failed to find similar logic in soc-core.c.
>
> Option 2. Machine driver borrows the reference count
>
> This is what [1] adopts.  Decreasing the reference count in device's
> remove() to make sure the object is valid for whole sound card's lifecycle.
>
> [1]: https://elixir.bootlin.com/linux/v5.16-rc5/source/sound/soc/mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c#L1065

I guess I have found the answer to my original questions.  The of_node
in snd_soc_dai_link_component in snd_soc_dai_link is mainly for
matching the component[4].  snd_soc_component itself should hold the
reference count.

[4]: https://elixir.bootlin.com/linux/v5.16-rc6/source/sound/soc/soc-core.c#L749

In summary:
- ASoC doesn't need to hold the device_node reference counts.
- Device nodes can be released after components have bound.

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

* Re: [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak
@ 2021-12-24  6:21   ` Tzung-Bi Shih
  0 siblings, 0 replies; 9+ messages in thread
From: Tzung-Bi Shih @ 2021-12-24  6:21 UTC (permalink / raw)
  To: broonie, lgirdwood, perex, tiwai
  Cc: alsa-devel, linux-arm-kernel, linux-mediatek,
	Jiaxin Yu (俞家鑫)

On Tue, Dec 14, 2021 at 12:00 PM Tzung-Bi Shih <tzungbi@google.com> wrote:
> Option 1. Machine driver makes sure the object is valid until registered
>
> This patch adopts the option.  It needs snd_soc_register_card() to call
> of_node_get() somewhere to hold the reference count of of_node.  However,
> I failed to find similar logic in soc-core.c.
>
> Option 2. Machine driver borrows the reference count
>
> This is what [1] adopts.  Decreasing the reference count in device's
> remove() to make sure the object is valid for whole sound card's lifecycle.
>
> [1]: https://elixir.bootlin.com/linux/v5.16-rc5/source/sound/soc/mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c#L1065

I guess I have found the answer to my original questions.  The of_node
in snd_soc_dai_link_component in snd_soc_dai_link is mainly for
matching the component[4].  snd_soc_component itself should hold the
reference count.

[4]: https://elixir.bootlin.com/linux/v5.16-rc6/source/sound/soc/soc-core.c#L749

In summary:
- ASoC doesn't need to hold the device_node reference counts.
- Device nodes can be released after components have bound.

_______________________________________________
Linux-mediatek mailing list
Linux-mediatek@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-mediatek

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

* Re: [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak
@ 2021-12-24  6:21   ` Tzung-Bi Shih
  0 siblings, 0 replies; 9+ messages in thread
From: Tzung-Bi Shih @ 2021-12-24  6:21 UTC (permalink / raw)
  To: broonie, lgirdwood, perex, tiwai
  Cc: alsa-devel, linux-arm-kernel, linux-mediatek,
	Jiaxin Yu (俞家鑫)

On Tue, Dec 14, 2021 at 12:00 PM Tzung-Bi Shih <tzungbi@google.com> wrote:
> Option 1. Machine driver makes sure the object is valid until registered
>
> This patch adopts the option.  It needs snd_soc_register_card() to call
> of_node_get() somewhere to hold the reference count of of_node.  However,
> I failed to find similar logic in soc-core.c.
>
> Option 2. Machine driver borrows the reference count
>
> This is what [1] adopts.  Decreasing the reference count in device's
> remove() to make sure the object is valid for whole sound card's lifecycle.
>
> [1]: https://elixir.bootlin.com/linux/v5.16-rc5/source/sound/soc/mediatek/mt8195/mt8195-mt6359-rt1019-rt5682.c#L1065

I guess I have found the answer to my original questions.  The of_node
in snd_soc_dai_link_component in snd_soc_dai_link is mainly for
matching the component[4].  snd_soc_component itself should hold the
reference count.

[4]: https://elixir.bootlin.com/linux/v5.16-rc6/source/sound/soc/soc-core.c#L749

In summary:
- ASoC doesn't need to hold the device_node reference counts.
- Device nodes can be released after components have bound.

_______________________________________________
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] 9+ messages in thread

end of thread, other threads:[~2021-12-24  6:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14  4:00 [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak Tzung-Bi Shih
2021-12-14  4:00 ` Tzung-Bi Shih
2021-12-14  4:00 ` Tzung-Bi Shih
2021-12-23 19:39 ` Mark Brown
2021-12-23 19:39   ` Mark Brown
2021-12-23 19:39   ` Mark Brown
2021-12-24  6:21 ` Tzung-Bi Shih
2021-12-24  6:21   ` Tzung-Bi Shih
2021-12-24  6:21   ` Tzung-Bi Shih

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.