Skip to contentSkip to conversation

ASoC: mediatek: mt8192-mt6359: fix device_node leak

RFC PATCH In review Tzung-Bi Shih 2 participants 3 messages Dec 14, 2021 – Dec 24, 2021

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

RFC PATCH 1/1 ASoC: mediatek: mt8192-mt6359: fix device_node leak

The of_parse_phandle() document:

Quoted 1 line
Quoted 1 line
Quoted 1 line

Use of_node_put() on it when done.

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

---
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]:

Quoted 1 line
Quoted 1 line
Quoted 1 line

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(-)
sound/soc/mediatek/mt8192/mt8192-mt6359-rt1015-rt5682.c +5 -1
index a606133951b7..24a5d0adec1b 100644
@@ -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
Signature · 7 lines
2.34.1.173.g76aa8bc2d0-goog


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
maintainer
#1 lore raw
Quoted 6 lines · Tzung-Bi Shih

The of_parse_phandle() document:

Quoted 1 line
Quoted 1 line
Quoted 1 line

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
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#2 lore raw
In reply to Tzung-Bi Shih
Quoted 6 lines · Tzung-Bi Shih

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.

Quoted 6 lines

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
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek