[PATCH AUTOSEL 5.17 63/66] ASoC: mediatek: Fix error handling in mt8183_da7219_max98357_dev_probe
Sasha Levin
sashal at kernel.org
Wed Mar 30 13:46:42 CEST 2022
From: Miaoqian Lin <linmq006 at gmail.com>
[ Upstream commit 28a265a1ee11febeec5ea73a804f30dcec3181ca ]
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.
Signed-off-by: Miaoqian Lin <linmq006 at gmail.com>
Reviewed-by: Tzung-Bi Shih <tzungbi at kernel.org>
Link: https://lore.kernel.org/r/20220316014059.19292-1-linmq006@gmail.com
Signed-off-by: Mark Brown <broonie at kernel.org>
Signed-off-by: Sasha Levin <sashal at kernel.org>
---
.../mediatek/mt8183/mt8183-da7219-max98357.c | 23 +++++++++++++------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
index 718505c75418..f090dee0c7a4 100644
--- a/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
+++ b/sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c
@@ -695,8 +695,11 @@ static int mt8183_da7219_max98357_dev_probe(struct platform_device *pdev)
}
card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev);
- if (!card)
- return -EINVAL;
+ if (!card) {
+ ret = -EINVAL;
+ goto put_platform_node;
+ }
+
card->dev = &pdev->dev;
hdmi_codec = of_parse_phandle(pdev->dev.of_node,
@@ -761,12 +764,15 @@ static int mt8183_da7219_max98357_dev_probe(struct platform_device *pdev)
if (!mt8183_da7219_max98357_headset_dev.dlc.of_node) {
dev_err(&pdev->dev,
"Property 'mediatek,headset-codec' missing/invalid\n");
- return -EINVAL;
+ ret = -EINVAL;
+ goto put_hdmi_codec;
}
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
- if (!priv)
- return -ENOMEM;
+ if (!priv) {
+ ret = -ENOMEM;
+ goto put_hdmi_codec;
+ }
snd_soc_card_set_drvdata(card, priv);
@@ -775,13 +781,16 @@ static int mt8183_da7219_max98357_dev_probe(struct platform_device *pdev)
ret = PTR_ERR(pinctrl);
dev_err(&pdev->dev, "%s failed to select default state %d\n",
__func__, ret);
- return ret;
+ goto put_hdmi_codec;
}
ret = devm_snd_soc_register_card(&pdev->dev, card);
- of_node_put(platform_node);
+
+put_hdmi_codec:
of_node_put(hdmi_codec);
+put_platform_node:
+ of_node_put(platform_node);
return ret;
}
--
2.34.1
More information about the Alsa-devel
mailing list