Skip to content

Commit

Permalink
ASoC: tegra: Convert to managed resources
Browse files Browse the repository at this point in the history
Use managed resource functions devm_clk_put and
devm_snd_soc_register_component to simplify error handling.

To be compatible with the change various gotos are replaced
with direct returns, and unneeded labels are dropped.

Signed-off-by: Vaishali Thakkar <vthakkar1994@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Vaishali Thakkar authored and Mark Brown committed Aug 14, 2015
1 parent 8833c01 commit 470805e
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions sound/soc/tegra/tegra20_spdif.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,53 +273,48 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
GFP_KERNEL);
if (!spdif) {
dev_err(&pdev->dev, "Can't allocate tegra20_spdif\n");
ret = -ENOMEM;
goto err;
return -ENOMEM;
}
dev_set_drvdata(&pdev->dev, spdif);

spdif->clk_spdif_out = clk_get(&pdev->dev, "spdif_out");
spdif->clk_spdif_out = devm_clk_get(&pdev->dev, "spdif_out");
if (IS_ERR(spdif->clk_spdif_out)) {
pr_err("Can't retrieve spdif clock\n");
ret = PTR_ERR(spdif->clk_spdif_out);
goto err;
return ret;
}

mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!mem) {
dev_err(&pdev->dev, "No memory resource\n");
ret = -ENODEV;
goto err_clk_put;
return -ENODEV;
}

dmareq = platform_get_resource(pdev, IORESOURCE_DMA, 0);
if (!dmareq) {
dev_err(&pdev->dev, "No DMA resource\n");
ret = -ENODEV;
goto err_clk_put;
return -ENODEV;
}

memregion = devm_request_mem_region(&pdev->dev, mem->start,
resource_size(mem), DRV_NAME);
if (!memregion) {
dev_err(&pdev->dev, "Memory region already claimed\n");
ret = -EBUSY;
goto err_clk_put;
return -EBUSY;
}

regs = devm_ioremap(&pdev->dev, mem->start, resource_size(mem));
if (!regs) {
dev_err(&pdev->dev, "ioremap failed\n");
ret = -ENOMEM;
goto err_clk_put;
return -ENOMEM;
}

spdif->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
&tegra20_spdif_regmap_config);
if (IS_ERR(spdif->regmap)) {
dev_err(&pdev->dev, "regmap init failed\n");
ret = PTR_ERR(spdif->regmap);
goto err_clk_put;
return ret;
}

spdif->playback_dma_data.addr = mem->start + TEGRA20_SPDIF_DATA_OUT;
Expand All @@ -334,8 +329,9 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
goto err_pm_disable;
}

ret = snd_soc_register_component(&pdev->dev, &tegra20_spdif_component,
&tegra20_spdif_dai, 1);
ret = devm_snd_soc_register_component(&pdev->dev,
&tegra20_spdif_component,
&tegra20_spdif_dai, 1);
if (ret) {
dev_err(&pdev->dev, "Could not register DAI: %d\n", ret);
ret = -ENOMEM;
Expand All @@ -345,21 +341,17 @@ static int tegra20_spdif_platform_probe(struct platform_device *pdev)
ret = tegra_pcm_platform_register(&pdev->dev);
if (ret) {
dev_err(&pdev->dev, "Could not register PCM: %d\n", ret);
goto err_unregister_component;
return ret;
}

return 0;

err_unregister_component:
snd_soc_unregister_component(&pdev->dev);
err_suspend:
if (!pm_runtime_status_suspended(&pdev->dev))
tegra20_spdif_runtime_suspend(&pdev->dev);
err_pm_disable:
pm_runtime_disable(&pdev->dev);
err_clk_put:
clk_put(spdif->clk_spdif_out);
err:

return ret;
}

Expand All @@ -372,9 +364,6 @@ static int tegra20_spdif_platform_remove(struct platform_device *pdev)
tegra20_spdif_runtime_suspend(&pdev->dev);

tegra_pcm_platform_unregister(&pdev->dev);
snd_soc_unregister_component(&pdev->dev);

clk_put(spdif->clk_spdif_out);

return 0;
}
Expand Down

0 comments on commit 470805e

Please sign in to comment.