Skip to content

Commit 28a265a

Browse files
Yuuoniybroonie
authored andcommitted
ASoC: mediatek: Fix error handling in mt8183_da7219_max98357_dev_probe
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@gmail.com> Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org> Link: https://lore.kernel.org/r/20220316014059.19292-1-linmq006@gmail.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 740dc3e commit 28a265a

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

sound/soc/mediatek/mt8183/mt8183-da7219-max98357.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,11 @@ static int mt8183_da7219_max98357_dev_probe(struct platform_device *pdev)
695695
}
696696

697697
card = (struct snd_soc_card *)of_device_get_match_data(&pdev->dev);
698-
if (!card)
699-
return -EINVAL;
698+
if (!card) {
699+
ret = -EINVAL;
700+
goto put_platform_node;
701+
}
702+
700703
card->dev = &pdev->dev;
701704

702705
hdmi_codec = of_parse_phandle(pdev->dev.of_node,
@@ -761,12 +764,15 @@ static int mt8183_da7219_max98357_dev_probe(struct platform_device *pdev)
761764
if (!mt8183_da7219_max98357_headset_dev.dlc.of_node) {
762765
dev_err(&pdev->dev,
763766
"Property 'mediatek,headset-codec' missing/invalid\n");
764-
return -EINVAL;
767+
ret = -EINVAL;
768+
goto put_hdmi_codec;
765769
}
766770

767771
priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
768-
if (!priv)
769-
return -ENOMEM;
772+
if (!priv) {
773+
ret = -ENOMEM;
774+
goto put_hdmi_codec;
775+
}
770776

771777
snd_soc_card_set_drvdata(card, priv);
772778

@@ -775,13 +781,16 @@ static int mt8183_da7219_max98357_dev_probe(struct platform_device *pdev)
775781
ret = PTR_ERR(pinctrl);
776782
dev_err(&pdev->dev, "%s failed to select default state %d\n",
777783
__func__, ret);
778-
return ret;
784+
goto put_hdmi_codec;
779785
}
780786

781787
ret = devm_snd_soc_register_card(&pdev->dev, card);
782788

783-
of_node_put(platform_node);
789+
790+
put_hdmi_codec:
784791
of_node_put(hdmi_codec);
792+
put_platform_node:
793+
of_node_put(platform_node);
785794
return ret;
786795
}
787796

0 commit comments

Comments
 (0)