[RFC PATCH] ASoC: mediatek: mt8192-mt6359: fix device_node leak
Tzung-Bi Shih
tzungbi at google.com
Mon Dec 13 20:00:28 PST 2021
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 at 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
More information about the linux-arm-kernel
mailing list