ASoC: sun4i-codec: Fix OF node reference leaks for analog controls
Subsystems (3)
PATCH 1/1 ASoC: sun4i-codec: Fix OF node reference leaks for analog controls
The device node obtained from of_parse_phandle() for "allwinner,codec-analog-controls" in sun8i_a23_codec_create_card(), sun8i_h3_codec_create_card(), and sun8i_v3s_codec_create_card() has its reference count incremented by of_parse_phandle().
However, the driver fails to drop this reference count when sun4i_codec_create_link() fails, when snd_soc_register_card() fails in sun4i_codec_probe(), or when the driver is removed in sun4i_codec_remove().
Fix this by adding the missing of_node_put(aux_dev.dlc.of_node) calls in these error paths and in sun4i_codec_remove().
--- sound/soc/sunxi/sun4i-codec.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
sound/soc/sunxi/sun4i-codec.c +16 -3
@@ -1429,8 +1429,11 @@ static struct snd_soc_card *sun8i_a23_codec_create_card(struct device *dev) } card->dai_link =sun4i_codec_create_link (dev, &card->num_links); -if (!card->dai_link) +if (!card->dai_link) { +of_node_put (aux_dev.dlc.of_node); + aux_dev.dlc.of_node =NULL ;return ERR_PTR (-ENOMEM ); + } card->dev = dev; card->owner =THIS_MODULE ;
@@ -1468,8 +1471,11 @@ static struct snd_soc_card *sun8i_h3_codec_create_card(struct device *dev) } card->dai_link =sun4i_codec_create_link (dev, &card->num_links); -if (!card->dai_link) +if (!card->dai_link) { +of_node_put (aux_dev.dlc.of_node); + aux_dev.dlc.of_node =NULL ;return ERR_PTR (-ENOMEM ); + } card->dev = dev; card->owner =THIS_MODULE ;
@@ -1507,8 +1513,11 @@ static struct snd_soc_card *sun8i_v3s_codec_create_card(struct device *dev) } card->dai_link =sun4i_codec_create_link (dev, &card->num_links); -if (!card->dai_link) +if (!card->dai_link) { +of_node_put (aux_dev.dlc.of_node); + aux_dev.dlc.of_node =NULL ;return ERR_PTR (-ENOMEM ); + } card->dev = dev; card->owner =THIS_MODULE ;
@@ -1808,6 +1817,8 @@ static int sun4i_codec_probe(struct platform_device *pdev) ret =snd_soc_register_card (card);if (ret) {dev_err_probe (&pdev->dev, ret,"Failed to register our card\n" ); +of_node_put (aux_dev.dlc.of_node); + aux_dev.dlc.of_node =NULL ; goto err_assert_reset; }
@@ -1830,6 +1841,8 @@ static int sun4i_codec_remove(struct platform_device *pdev)if (scodec->rst)reset_control_assert (scodec->rst);clk_disable_unprepare (scodec->clk_apb); +of_node_put (aux_dev.dlc.of_node); + aux_dev.dlc.of_node =NULL ;return 0 ; }
Signature · 1 line
2.55.0.windows.4
Mark Brown
maintainerQuoted 4 lines · Sushanto
The device node obtained from
of_parse_phandle()for "allwinner,codec-analog-controls" insun8i_a23_codec_create_card(),sun8i_h3_codec_create_card(), andsun8i_v3s_codec_create_card()has its reference count incremented byof_parse_phandle().
This doesn't apply against current code, please check and resend.