diff mbox series

[1/3] mmc: sunlpus: Fix an error handling path in spmmc_drv_probe()

Message ID 7c686fecb11b4ec1f55cd7075dc7cfcdd9b445ba.1670697358.git.christophe.jaillet@wanadoo.fr (mailing list archive)
State New, archived
Headers show
Series [1/3] mmc: sunlpus: Fix an error handling path in spmmc_drv_probe() | expand

Commit Message

Christophe JAILLET Dec. 10, 2022, 6:36 p.m. UTC
If an error occurs after successful clk_prepare_enable() call in the probe,
the clk is not clk_disable_unprepare()'ed.

Use devm_clk_get_enabled() instead of devm_clk_get() to fix, and simplify
the probe and the remove function accordingly.

Fixes: 4e268fed8b18 ("mmc: Add mmc driver for Sunplus SP7021")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
This changes the order of resource releasing when the driver is removed,
but it looks ok to me.
---
 drivers/mmc/host/sunplus-mmc.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

Comments

Christophe JAILLET Dec. 10, 2022, 6:56 p.m. UTC | #1
Le 10/12/2022 à 19:36, Christophe JAILLET a écrit :
> If an error occurs after successful clk_prepare_enable() call in the probe,
> the clk is not clk_disable_unprepare()'ed.
> 
> Use devm_clk_get_enabled() instead of devm_clk_get() to fix, and simplify
> the probe and the remove function accordingly.
> 
> Fixes: 4e268fed8b18 ("mmc: Add mmc driver for Sunplus SP7021")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> This changes the order of resource releasing when the driver is removed,
> but it looks ok to me.
> ---
>   drivers/mmc/host/sunplus-mmc.c | 7 +------
>   1 file changed, 1 insertion(+), 6 deletions(-)
> 

Hi, in the whole serie, the subject was supposed to be sunplus, not sunlpus.
Could also be SP7021, or sunplus-SP7021, or whatever else.

I'll wait for potential comments on the patches themselves before 
sending a v2 to fix the subject (and I hope it could be fixed when 
applied if there is no comment :))

CJ
Ulf Hansson Jan. 2, 2023, 12:49 p.m. UTC | #2
On Sat, 10 Dec 2022 at 19:36, Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> If an error occurs after successful clk_prepare_enable() call in the probe,
> the clk is not clk_disable_unprepare()'ed.
>
> Use devm_clk_get_enabled() instead of devm_clk_get() to fix, and simplify
> the probe and the remove function accordingly.
>
> Fixes: 4e268fed8b18 ("mmc: Add mmc driver for Sunplus SP7021")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---
> This changes the order of resource releasing when the driver is removed,
> but it looks ok to me.
> ---
>  drivers/mmc/host/sunplus-mmc.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
>
> diff --git a/drivers/mmc/host/sunplus-mmc.c b/drivers/mmc/host/sunplus-mmc.c
> index db5e0dcdfa7f..3e8856a82188 100644
> --- a/drivers/mmc/host/sunplus-mmc.c
> +++ b/drivers/mmc/host/sunplus-mmc.c
> @@ -878,7 +878,7 @@ static int spmmc_drv_probe(struct platform_device *pdev)
>         if (IS_ERR(host->base))
>                 return PTR_ERR(host->base);
>
> -       host->clk = devm_clk_get(&pdev->dev, NULL);
> +       host->clk = devm_clk_get_enabled(&pdev->dev, NULL);
>         if (IS_ERR(host->clk))
>                 return dev_err_probe(&pdev->dev, PTR_ERR(host->clk), "clk get fail\n");
>
> @@ -896,10 +896,6 @@ static int spmmc_drv_probe(struct platform_device *pdev)
>         if (ret)
>                 return ret;
>
> -       ret = clk_prepare_enable(host->clk);
> -       if (ret)
> -               return dev_err_probe(&pdev->dev, ret, "failed to enable clk\n");
> -
>         ret = mmc_of_parse(mmc);
>         if (ret)
>                 goto probe_free_host;
> @@ -944,7 +940,6 @@ static int spmmc_drv_remove(struct platform_device *dev)
>
>         mmc_remove_host(host->mmc);
>         pm_runtime_get_sync(&dev->dev);
> -       clk_disable_unprepare(host->clk);

I don't think this improves code quality, but rather the opposite.

Removing the call to clk_disable_unprepare() here, makes the untrained
eye, to believe that the calls to pm_runtime_get_sync() and
pm_runtime_put_noidle() are redundant, while they aren't.

Instead, I suggest we add a call to clk_disable_unprepare() in the
error path in ->probe(), rather than using devm_clk_get_enabled().

>         pm_runtime_put_noidle(&dev->dev);
>         pm_runtime_disable(&dev->dev);
>         platform_set_drvdata(dev, NULL);

Kind regards
Uffe
diff mbox series

Patch

diff --git a/drivers/mmc/host/sunplus-mmc.c b/drivers/mmc/host/sunplus-mmc.c
index db5e0dcdfa7f..3e8856a82188 100644
--- a/drivers/mmc/host/sunplus-mmc.c
+++ b/drivers/mmc/host/sunplus-mmc.c
@@ -878,7 +878,7 @@  static int spmmc_drv_probe(struct platform_device *pdev)
 	if (IS_ERR(host->base))
 		return PTR_ERR(host->base);
 
-	host->clk = devm_clk_get(&pdev->dev, NULL);
+	host->clk = devm_clk_get_enabled(&pdev->dev, NULL);
 	if (IS_ERR(host->clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(host->clk), "clk get fail\n");
 
@@ -896,10 +896,6 @@  static int spmmc_drv_probe(struct platform_device *pdev)
 	if (ret)
 		return ret;
 
-	ret = clk_prepare_enable(host->clk);
-	if (ret)
-		return dev_err_probe(&pdev->dev, ret, "failed to enable clk\n");
-
 	ret = mmc_of_parse(mmc);
 	if (ret)
 		goto probe_free_host;
@@ -944,7 +940,6 @@  static int spmmc_drv_remove(struct platform_device *dev)
 
 	mmc_remove_host(host->mmc);
 	pm_runtime_get_sync(&dev->dev);
-	clk_disable_unprepare(host->clk);
 	pm_runtime_put_noidle(&dev->dev);
 	pm_runtime_disable(&dev->dev);
 	platform_set_drvdata(dev, NULL);