All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tzung-Bi Shih <tzungbi@google.com>
To: broonie@kernel.org, lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com
Cc: alsa-devel@alsa-project.org, tzungbi@google.com,
	 linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak
Date: Tue, 14 Dec 2021 12:00:28 +0800	[thread overview]
Message-ID: <20211214040028.2992627-1-tzungbi@google.com> (raw)

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

WARNING: multiple messages have this Message-ID (diff)
From: Tzung-Bi Shih <tzungbi@google.com>
To: broonie@kernel.org, lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com
Cc: tzungbi@google.com, alsa-devel@alsa-project.org,
	linux-mediatek@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak
Date: Tue, 14 Dec 2021 12:00:28 +0800	[thread overview]
Message-ID: <20211214040028.2992627-1-tzungbi@google.com> (raw)

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


WARNING: multiple messages have this Message-ID (diff)
From: Tzung-Bi Shih <tzungbi@google.com>
To: broonie@kernel.org, lgirdwood@gmail.com, perex@perex.cz, tiwai@suse.com
Cc: alsa-devel@alsa-project.org, tzungbi@google.com,
	 linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: [RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak
Date: Tue, 14 Dec 2021 12:00:28 +0800	[thread overview]
Message-ID: <20211214040028.2992627-1-tzungbi@google.com> (raw)

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

             reply	other threads:[~2021-12-14  4:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-14  4:00 Tzung-Bi Shih [this message]
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-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

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=20211214040028.2992627-1-tzungbi@google.com \
    --to=tzungbi@google.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=perex@perex.cz \
    --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.