diff mbox series

[1/2] i2c: synquacer: Fix an error handling path in synquacer_i2c_probe()

Message ID a0fdf90803ab44508aa07f9190af5e00272231df.1704545258.git.christophe.jaillet@wanadoo.fr
State New
Headers show
Series [1/2] i2c: synquacer: Fix an error handling path in synquacer_i2c_probe() | expand

Commit Message

Christophe JAILLET Jan. 6, 2024, 12:48 p.m. UTC
If an error occurs after the clk_prepare_enable() call, it should be undone
by a corresponding clk_disable_unprepare() call, as already done in the
remove() function.

As devm_clk_get() is used, we can switch to devm_clk_get_enabled() to
handle it automatically and fix the probe.

Update the remove() function accordingly and remove the now useless
clk_disable_unprepare() call.

Fixes: 0d676a6c4390 ("i2c: add support for Socionext SynQuacer I2C controller")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/i2c/busses/i2c-synquacer.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

Comments

Ard Biesheuvel Jan. 12, 2024, 5:50 p.m. UTC | #1
On Sat, 6 Jan 2024 at 13:48, Christophe JAILLET
<christophe.jaillet@wanadoo.fr> wrote:
>
> If an error occurs after the clk_prepare_enable() call, it should be undone
> by a corresponding clk_disable_unprepare() call, as already done in the
> remove() function.
>
> As devm_clk_get() is used, we can switch to devm_clk_get_enabled() to
> handle it automatically and fix the probe.
>
> Update the remove() function accordingly and remove the now useless
> clk_disable_unprepare() call.
>
> Fixes: 0d676a6c4390 ("i2c: add support for Socionext SynQuacer I2C controller")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Acked-by: Ard Biesheuvel <ardb@kernel.org>

> ---
>  drivers/i2c/busses/i2c-synquacer.c | 20 +++++++-------------
>  1 file changed, 7 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/i2c/busses/i2c-synquacer.c b/drivers/i2c/busses/i2c-synquacer.c
> index bbea521b05dd..a73f5bb9a164 100644
> --- a/drivers/i2c/busses/i2c-synquacer.c
> +++ b/drivers/i2c/busses/i2c-synquacer.c
> @@ -550,17 +550,13 @@ static int synquacer_i2c_probe(struct platform_device *pdev)
>         device_property_read_u32(&pdev->dev, "socionext,pclk-rate",
>                                  &i2c->pclkrate);
>
> -       i2c->pclk = devm_clk_get(&pdev->dev, "pclk");
> -       if (PTR_ERR(i2c->pclk) == -EPROBE_DEFER)
> -               return -EPROBE_DEFER;
> -       if (!IS_ERR_OR_NULL(i2c->pclk)) {
> -               dev_dbg(&pdev->dev, "clock source %p\n", i2c->pclk);
> -
> -               ret = clk_prepare_enable(i2c->pclk);
> -               if (ret)
> -                       return dev_err_probe(&pdev->dev, ret, "failed to enable clock\n");
> -               i2c->pclkrate = clk_get_rate(i2c->pclk);
> -       }
> +       i2c->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
> +       if (IS_ERR(i2c->pclk))
> +               return dev_err_probe(&pdev->dev, PTR_ERR(i2c->pclk),
> +                                    "failed to get and enable clock\n");
> +
> +       dev_dbg(&pdev->dev, "clock source %p\n", i2c->pclk);
> +       i2c->pclkrate = clk_get_rate(i2c->pclk);
>
>         if (i2c->pclkrate < SYNQUACER_I2C_MIN_CLK_RATE ||
>             i2c->pclkrate > SYNQUACER_I2C_MAX_CLK_RATE)
> @@ -615,8 +611,6 @@ static void synquacer_i2c_remove(struct platform_device *pdev)
>         struct synquacer_i2c *i2c = platform_get_drvdata(pdev);
>
>         i2c_del_adapter(&i2c->adapter);
> -       if (!IS_ERR(i2c->pclk))
> -               clk_disable_unprepare(i2c->pclk);
>  };
>
>  static const struct of_device_id synquacer_i2c_dt_ids[] __maybe_unused = {
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/drivers/i2c/busses/i2c-synquacer.c b/drivers/i2c/busses/i2c-synquacer.c
index bbea521b05dd..a73f5bb9a164 100644
--- a/drivers/i2c/busses/i2c-synquacer.c
+++ b/drivers/i2c/busses/i2c-synquacer.c
@@ -550,17 +550,13 @@  static int synquacer_i2c_probe(struct platform_device *pdev)
 	device_property_read_u32(&pdev->dev, "socionext,pclk-rate",
 				 &i2c->pclkrate);
 
-	i2c->pclk = devm_clk_get(&pdev->dev, "pclk");
-	if (PTR_ERR(i2c->pclk) == -EPROBE_DEFER)
-		return -EPROBE_DEFER;
-	if (!IS_ERR_OR_NULL(i2c->pclk)) {
-		dev_dbg(&pdev->dev, "clock source %p\n", i2c->pclk);
-
-		ret = clk_prepare_enable(i2c->pclk);
-		if (ret)
-			return dev_err_probe(&pdev->dev, ret, "failed to enable clock\n");
-		i2c->pclkrate = clk_get_rate(i2c->pclk);
-	}
+	i2c->pclk = devm_clk_get_enabled(&pdev->dev, "pclk");
+	if (IS_ERR(i2c->pclk))
+		return dev_err_probe(&pdev->dev, PTR_ERR(i2c->pclk),
+				     "failed to get and enable clock\n");
+
+	dev_dbg(&pdev->dev, "clock source %p\n", i2c->pclk);
+	i2c->pclkrate = clk_get_rate(i2c->pclk);
 
 	if (i2c->pclkrate < SYNQUACER_I2C_MIN_CLK_RATE ||
 	    i2c->pclkrate > SYNQUACER_I2C_MAX_CLK_RATE)
@@ -615,8 +611,6 @@  static void synquacer_i2c_remove(struct platform_device *pdev)
 	struct synquacer_i2c *i2c = platform_get_drvdata(pdev);
 
 	i2c_del_adapter(&i2c->adapter);
-	if (!IS_ERR(i2c->pclk))
-		clk_disable_unprepare(i2c->pclk);
 };
 
 static const struct of_device_id synquacer_i2c_dt_ids[] __maybe_unused = {