diff mbox series

ASoC: sh: rz-ssi: Improve error handling in rz_ssi_probe() error path

Message ID 20220728090033.2414-1-biju.das.jz@bp.renesas.com (mailing list archive)
State Superseded
Headers show
Series ASoC: sh: rz-ssi: Improve error handling in rz_ssi_probe() error path | expand

Commit Message

Biju Das July 28, 2022, 9 a.m. UTC
We usually do cleanup in reverse order of init. Currently in case of
error rz_ssi_release_dma_channels() done in the reverse order. This
patch improves error handling in rz_ssi_probe() error path.

While at it, use "goto cleanup" style to reduce code duplication.

Reported-by: Pavel Machek <pavel@denx.de>
Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
---
 sound/soc/sh/rz-ssi.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

Comments

Biju Das July 28, 2022, 9:24 a.m. UTC | #1
Hi All,

> Biju Das <biju.das@bp.renesas.com>; linux-renesas-soc@vger.kernel.org;
> Pavel Machek <pavel@denx.de>
> Subject: [PATCH] ASoC: sh: rz-ssi: Improve error handling in
> rz_ssi_probe() error path
> 
> We usually do cleanup in reverse order of init. Currently in case of
> error rz_ssi_release_dma_channels() done in the reverse order. This
> patch improves error handling in rz_ssi_probe() error path.
> 
> While at it, use "goto cleanup" style to reduce code duplication.
> 
> Reported-by: Pavel Machek <pavel@denx.de>
> Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
> ---
>  sound/soc/sh/rz-ssi.c | 26 +++++++++++++++-----------
>  1 file changed, 15 insertions(+), 11 deletions(-)
> 
> diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c index
> 0d0594a0e4f6..c08ef317e3e3 100644
> --- a/sound/soc/sh/rz-ssi.c
> +++ b/sound/soc/sh/rz-ssi.c
> @@ -1017,32 +1017,36 @@ static int rz_ssi_probe(struct platform_device
> *pdev)
> 
>  	ssi->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
>  	if (IS_ERR(ssi->rstc)) {
> -		rz_ssi_release_dma_channels(ssi);
> -		return PTR_ERR(ssi->rstc);
> +		ret = PTR_ERR(ssi->rstc);
> +		goto err_dma;

This label needs to be changed to err_reset.
Will send V2.

Cheers,
Biju
diff mbox series

Patch

diff --git a/sound/soc/sh/rz-ssi.c b/sound/soc/sh/rz-ssi.c
index 0d0594a0e4f6..c08ef317e3e3 100644
--- a/sound/soc/sh/rz-ssi.c
+++ b/sound/soc/sh/rz-ssi.c
@@ -1017,32 +1017,36 @@  static int rz_ssi_probe(struct platform_device *pdev)
 
 	ssi->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL);
 	if (IS_ERR(ssi->rstc)) {
-		rz_ssi_release_dma_channels(ssi);
-		return PTR_ERR(ssi->rstc);
+		ret = PTR_ERR(ssi->rstc);
+		goto err_dma;
 	}
 
 	reset_control_deassert(ssi->rstc);
 	pm_runtime_enable(&pdev->dev);
 	ret = pm_runtime_resume_and_get(&pdev->dev);
 	if (ret < 0) {
-		rz_ssi_release_dma_channels(ssi);
-		pm_runtime_disable(ssi->dev);
-		reset_control_assert(ssi->rstc);
-		return dev_err_probe(ssi->dev, ret, "pm_runtime_resume_and_get failed\n");
+		dev_err(&pdev->dev, "pm_runtime_resume_and_get failed\n");
+		goto err_pm;
 	}
 
 	ret = devm_snd_soc_register_component(&pdev->dev, &rz_ssi_soc_component,
 					      rz_ssi_soc_dai,
 					      ARRAY_SIZE(rz_ssi_soc_dai));
 	if (ret < 0) {
-		rz_ssi_release_dma_channels(ssi);
-
-		pm_runtime_put(ssi->dev);
-		pm_runtime_disable(ssi->dev);
-		reset_control_assert(ssi->rstc);
 		dev_err(&pdev->dev, "failed to register snd component\n");
+		goto err_snd_soc;
 	}
 
+	return 0;
+
+err_snd_soc:
+	pm_runtime_put(ssi->dev);
+err_pm:
+	pm_runtime_disable(ssi->dev);
+	reset_control_assert(ssi->rstc);
+err_dma:
+	rz_ssi_release_dma_channels(ssi);
+
 	return ret;
 }