Skip to content

Commit

Permalink
ASoC: atmel: Fix error handling in sam9x5_wm8731_driver_probe
Browse files Browse the repository at this point in the history
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 path.

Fixes: fdbcb3c ("ASoC: atmel: machine driver for at91sam9x5-wm8731 boards")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Reviewed-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
Link: https://lore.kernel.org/r/20220316111530.4551-1-linmq006@gmail.com
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Miaoqian Lin authored and Mark Brown committed Mar 16, 2022
1 parent cc5d8ac commit 740dc3e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions sound/soc/atmel/sam9x5_wm8731.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static int sam9x5_wm8731_driver_probe(struct platform_device *pdev)
if (!cpu_np) {
dev_err(&pdev->dev, "atmel,ssc-controller node missing\n");
ret = -EINVAL;
goto out;
goto out_put_codec_np;
}
dai->cpus->of_node = cpu_np;
dai->platforms->of_node = cpu_np;
Expand All @@ -153,12 +153,9 @@ static int sam9x5_wm8731_driver_probe(struct platform_device *pdev)
if (ret != 0) {
dev_err(&pdev->dev, "Failed to set SSC %d for audio: %d\n",
ret, priv->ssc_id);
goto out;
goto out_put_cpu_np;
}

of_node_put(codec_np);
of_node_put(cpu_np);

ret = devm_snd_soc_register_card(&pdev->dev, card);
if (ret) {
dev_err(&pdev->dev, "Platform device allocation failed\n");
Expand All @@ -167,10 +164,14 @@ static int sam9x5_wm8731_driver_probe(struct platform_device *pdev)

dev_dbg(&pdev->dev, "%s ok\n", __func__);

return ret;
goto out_put_cpu_np;

out_put_audio:
atmel_ssc_put_audio(priv->ssc_id);
out_put_cpu_np:
of_node_put(cpu_np);
out_put_codec_np:
of_node_put(codec_np);
out:
return ret;
}
Expand Down

0 comments on commit 740dc3e

Please sign in to comment.